Username and password in access form

holzy

New member
Local time
Today, 22:02
Joined
May 7, 2010
Messages
2
IS there an easy way i can get a username and password form working, where if its correct it goes to another form and if its incorrect it comes up with an error message? Any help would be useful, thanls!!

x
 
I followed a similar path to the example above and also added a [security] field to the Users table.
When the user logs in the [security] value is held on the switchboard screen. When any form is opened I set the OnCurrent event to SetSecurity, this looks at the module below and switches available menu bars and hides and buttons which might not be suitable for the current user's level of security.
I think it works pretty well and be exanded easily. :D

Code:
Public Function SetSecurity()
On Error GoTo Err_Handler
Dim intSec As Integer
Dim frmCurrentForm As Form
        intSec = [Forms]![Switchboard].LLSecurity
        Select Case intSec
        
            Case 999 'Super User settings
                CommandBars.Item("LL").Enabled = True
                CommandBars.Item("Print Preview").Enabled = True
                            Dim i As Integer                'ADMIN USE ONLY REMOVE LINE ON INSTALL
                            For i = 1 To CommandBars.Count  'ADMIN USE ONLY REMOVE LINE ON INSTALL
                            CommandBars(i).Enabled = True   'ADMIN USE ONLY REMOVE LINE ON INSTALL
                            Next i                          'ADMIN USE ONLY REMOVE LINE ON INSTALL
                CommandBars.Item("Admin").Enabled = False
                CommandBars.Item("Adv").Enabled = False
                DoCmd.ShowToolbar "LL", acToolbarYes
                Set frmCurrentForm = Screen.ActiveForm
                With frmCurrentForm
                    .ShortcutMenu = True
                End With
            
            Case 899 'Branch Admin - No access to User List controls
                CommandBars.Item("LL").Enabled = True
                CommandBars.Item("Print Preview").Enabled = True
                CommandBars.Item("Admin").Enabled = False
                CommandBars.Item("Adv").Enabled = False
                DoCmd.ShowToolbar "LL", acToolbarYes
                Set frmCurrentForm = Screen.ActiveForm
                With frmCurrentForm
                    .ShortcutMenu = True
                    .selBR = DLookup("[Branch]", "LLUsers", "[UserName] ='" & [Forms]![Switchboard].[UserName] & "'")
                    .selBR.Locked = True
                    .selBR.Enabled = False
                End With
                
            Case 801 ' Admin - No Financials and No MI menu options
                CommandBars.Item("Admin").Enabled = True
                CommandBars.Item("Print Preview").Enabled = True
                CommandBars.Item("LL").Enabled = False
                CommandBars.Item("Adv").Enabled = False
                DoCmd.ShowToolbar "Admin", acToolbarYes
                Set frmCurrentForm = Screen.ActiveForm
                With frmCurrentForm
                    .ShortcutMenu = True
                    .cmdFin.Visible = False
                    .Refresh
                End With
                
            Case 199 'Advisor view settings
                CommandBars.Item("Adv").Enabled = True
                CommandBars.Item("Print Preview").Enabled = True
                CommandBars.Item("LL").Enabled = False
                CommandBars.Item("Admin").Enabled = False
                DoCmd.ShowToolbar "Adv", acToolbarYes
                Set frmCurrentForm = Screen.ActiveForm
                With frmCurrentForm
                    .cmdEdit.Visible = True
                    .cmdAddNew.Visible = False
                    .cmdAddNewNote.Visible = True
                    .cmdDel.Visible = False
                    .cmdSave.Visible = True
                    '.cmdReset.Visible = False
                    .SelCRa = DLookup("[Co Name]", "Parties", "[Agency No] ='" & [Forms]![Switchboard].[UserName] & "'")
                    .SelCRa.Locked = True
                    .SelCRa.Enabled = False
                    .selCR = [Forms]![Switchboard].[UserName]
                    .selCR.Locked = True
                    .selCR.Enabled = False
                    .ShortcutMenu = False
                    .Refresh
                End With
                
            Case 198 'Advisor view settings with ALL menu options but no delete functions
                
                CommandBars.Item("LL").Enabled = True
                CommandBars.Item("Print Preview").Enabled = True
                CommandBars.Item("Admin").Enabled = False
                CommandBars.Item("Adv").Enabled = False
                DoCmd.ShowToolbar "LL", acToolbarYes
                Set frmCurrentForm = Screen.ActiveForm
                With frmCurrentForm
                    .cmdEdit.Visible = True
                    .cmdAddNew.Visible = True
                    .cmdAddNewNote.Visible = True
                    .cmdDel.Visible = False
                    .cmdSave.Visible = True
                    '.cmdReset.Visible = False
                    .SelCRa = DLookup("[Co Name]", "Parties", "[Agency No] ='" & [Forms]![Switchboard].[UserName] & "'")
                    .SelCRa.Locked = True
                    .SelCRa.Enabled = False
                    .selCR = [Forms]![Switchboard].[UserName]
                    .selCR.Locked = True
                    .selCR.Enabled = False
                    .ShortcutMenu = False
                    .Refresh
                End With
                
            Case 101 ' As Advisor without Export and Print function
                CommandBars.Item("Adv").Enabled = True
                CommandBars.Item("LL").Enabled = False
                CommandBars.Item("Admin").Enabled = False
                DoCmd.ShowToolbar "Adv", acToolbarYes
                Set frmCurrentForm = Screen.ActiveForm
                With frmCurrentForm
                    .cmdEdit.Visible = True
                    .cmdAddNew.Visible = False
                    .cmdAddNewNote.Visible = False
                    .cmdDel.Visible = False
                    .cmdSave.Visible = True
                    .cmdReset.Visible = False
                    .SelCRa = DLookup("[Co Name]", "Parties", "[Agency No] ='" & [Forms]![Switchboard].[UserName] & "'")
                    .SelCRa.Locked = True
                    .SelCRa.Enabled = False
                    .selCR = [Forms]![Switchboard].[UserName]
                    .selCR.Locked = True
                    .selCR.Enabled = False
                    .cmdExport.Visible = False
                    .cmdPrint.Visible = False
                    .[cmdPrint-PA].Visible = False
                    .cmdPrintRev.Visible = False
                    .ShortcutMenu = False
                    .Refresh
                End With
                
            Case Else 'Not sure the purpose of this option, relates to default 111 setting
                CommandBars.Item("Adv").Enabled = True
                CommandBars.Item("LL").Enabled = False
                CommandBars.Item("Admin").Enabled = False
                DoCmd.ShowToolbar "Adv", acToolbarYes
                Set frmCurrentForm = Screen.ActiveForm
                With frmCurrentForm
                    .cmdEdit.Visible = False
                    .cmdAddNew.Visible = False
                    .cmdAddNewNote.Visible = False
                    .cmdDel.Visible = False
                    .cmdSave.Visible = False
                    .cmdExport.Visible = False
                    .cmdPrint.Visible = False
                    .[cmdPrint-PA].Visible = False
                    .cmdPrintRev.Visible = False
                    .ShortcutMenu = False
                    .Refresh
                End With
End Select
Exit Function
Err_Handler:
    If err.Number = 2465 Then
        Resume Next
    End If
    MsgBox err.Description & " / " & err.Number
End Function
 

Users who are viewing this thread

Back
Top Bottom