Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2013
    Posts
    11

    Exclamation Unanswered: MS Access Login Form VBA Syntax Error

    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,

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Although I don't understand why you bother to use your own login form, the errors probablycomes from:
    Code:
    If Me.txtPassword.Value = DLookup("Password", "qryFullName", " [SolicitorID]=" & Me.cboEmployee.Value) Then
    which should be:
    Code:
    If Me.txtPassword.Value = DLookup("Password", "qryFullName", " [SolicitorID]='" & Me.cboEmployee.Value & "'") Then
    as the message seems to indicate: ' [SolicitorID]=Kate Smith'.
    Have a nice day!

  3. #3
    Join Date
    Feb 2013
    Posts
    11
    Thanks for the response, however;

    The new code you suggested displays a new error that is;

    Run-time error 3464

    Data type is mismatch in criteria expression.


    The [SolicitorID] field is obviously an AutoNumber, could this has anything to do with it, and how should I alter the code if so?

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so?
    the problem is that you are supplying a string value, yet you know the column is actually numeric
    you need to make certain you are pulling the correct column from the combobox
    and it still begs the question why you are writing your own logon form, and spending development time supporting it.
    google dev ashish api or look in the code bank
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Feb 2013
    Posts
    11
    Thank you very much for being incredibly helpful. I didn't come here for advice on how to spend development time. I unsurprisingly came here for some assistance with the small problem that I have since resolved myself.

    I shall not be using these forums any time soon.

    Goodnight.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •