Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

MS Access Login Form VBA Syntax Error

$
0
0
I am attempting to produce a login form that requests the user to select their name from a drop down List Box (of which the source of the data is a query called 'qryFullName' and the field name 'Fullname' - that has combined data within the Forename and Surname fields of a table called 'tblSolicitors') and then enter a password before clicking Login.

The code for the Login button is as follows;

Code:


Option Compare Database
Private intLogonAttempts As Integer

Private Sub cmdExit_Click()
DoCmd.Quit
End Sub

Private Sub cmdLogin_Click()

'Check to see Employee has been selected in the combo box

    If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
            MsgBox "Please select an employee", vbOKOnly, "Required Data"
            Me.cboEmployee.SetFocus
        Exit Sub
    End If

'Check to see if data is entered into the password box


    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
            MsgBox "Please enter a password", vbOKOnly, "Required Data"
            Me.txtPassword.SetFocus
        Exit Sub
    End If
     
'Check value of password in qryFullName to see if this matches value chosen in combo box

    If Me.txtPassword.Value = DLookup("Password", "qryFullName", " [SolicitorID]=" & Me.cboEmployee.Value) Then
   
        MySolicitorID = Me.cboEmployee.Value


'Close logon form and open Switchboard
       
        DoCmd.Close acForm, "frmLogin", acSaveNo
        DoCmd.OpenForm "Switchboard"

        Else
        MsgBox "Incorrect password. Please Try Again", vbCritical + vbOKOnly, "Invalid Entry"
        Me.txtPassword.SetFocus
    End If
   
'If User Enters incorrect password 3 times database will shutdown
   
    intLogonAttempts = intLogonAttempts + 1
    If intLogonAttempts > 3 Then
        MsgBox "You do not have the correct permissions to access this database.  Please contact your system administrator.", vbCritical, "Access Restricted"
        Application.Quit
    End If
   
End Sub

The section of code I have displayed in bold is where I am having difficulty. This may be entirely wrong, in which case help would be appreciated, but when I click Login is displays the following message;

Run-time error 3705

Syntax error (missing operator) in query expression ' [SolicitorID]=Kate Smith'.


Many thanks,

Viewing all articles
Browse latest Browse all 13329

Trending Articles