Results 1 to 11 of 11
  1. #1
    VicLetran is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    16

    The expression you entered as a query produced this error "UserName". Correct the code.

    This is the Code: (Please anyone, correct this)

    Option Compare Database
    Option Explicit
    Dim intCount As Integer




    Private Sub cmdCancel_Click()
    DoCmd.Quit
    End Sub


    Private Sub cmdOK_Click()
    On Error GoTo ValidUserError


    If IsNull([txtUserPassword]) Or Len([txtUserPassword]) < 8 Or Len(txtUserName) < 8 Then
    MsgBox "Invalid User Name or Password", vbCritical, "Logon Error"
    [txtUserName].SetFocus
    Exit Sub
    Else
    'Validate the user name and password
    If DCount("UserName", "qryCurrentUser") = 1 Then 'limit the number of concurrent sessions allowed for each user
    'txtUserID = DLookup("UserID", "qryCurrentUser")
    ' txtDept = DLookup("EmployeeDept", "qryCurrentUser")

    'Use only if we need to validate the admin user
    'If DLookup("[Admin?]", "qryCurrentUser") Then
    DoCmd.OpenForm "Navigation Form"
    Forms!frmLogon.Visible = False
    'Else
    'Dim stFilter As String
    'stFilter = "DeptID = " & DLookup("EmployeeDept", "qryCurrentUser")
    'DoCmd.OpenForm "Switchboard", , , stFilter
    'Forms!frmLogon.Visible = False
    'End If
    Else
    MsgBox "Error Validating User.", vbCritical, "Logon Error"
    End If


    End If

    ValidUserExit:
    Exit Sub

    ValidUserError:
    MsgBox Err.Description
    Resume ValidUserExit



    End Sub


    Private Sub txtUserName_AfterUpdate()
    If IsNull([txtUserName]) Then
    MsgBox "Please enter User Name", vbCritical, "Logon User Name"
    [txtUserName].SetFocus
    End If
    End Sub


    Private Sub txtUserPassword_AfterUpdate()
    If IsNull([txtUserPassword]) Or Len([txtUserPassword]) < 8 Then
    MsgBox "Invalid Password", vbCritical, "Logon User Name"
    [txtUserPassword].SetFocus
    End If
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    you could show us which line the error happened.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Words are free in this forum.
    Please use as many as you need to describe the problem...


    BTW, the forum has lots of posts about log-in forms and problems with log-in code. Have you searched for posts about log-in form problems?

  4. #4
    John_G is offline VIP
    Windows 10 Access 2016
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Your error may be here:

    DCount("UserName", "qryCurrentUser") = 1
    Is UserName a field in the query qrycurrentUser?

    Also, that DCount doesn't seem to make sense - there is no Where clause in it, so it may be giving you the count of ALL the records in the query. Does qrycurrentUser have criteria in it so that it returns only records for the current user?

  5. #5
    VicLetran is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    16
    That pop up just appeared, I cannot trace which line got an error.

  6. #6
    John_G is offline VIP
    Windows 10 Access 2016
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    That pop up just appeared, I cannot trace which line got an error.
    It may be that ther error is not in the code you posted, but is in the code for one of the forms. If you do not see the "debug" option on the error message box, it is probably coming from an error handler in one of the Sub's.

    Try turning off all error handling:

    - Open any code module
    - From the menu, Select Tools - Options
    - Click the "General" tab in the dialog
    - In the "Error Trapping" section, select the "Break on all errors" option
    - Close the dialog and the VBA module

    Run your code again; this time you should get a genuine runtime error dialog. Click the "Debug" button, and the VBA editing screen will open, with the offending line highlighted in yellow.

  7. #7
    VicLetran is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    16
    Ok. I created the login files tbluser, loginform, queary in other file and it works. so i just copied it to my other file, when I copied it , it no longer worked successful, and prompt that error

  8. #8
    VicLetran is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    16
    It did not work. I tried to create another LoginForm. (Sorry I am new in MS Access). I almost got it but there is error in the codes below that I cannot fix: here it is please help. Thanks in Advance.

    Option Compare Database


    Private Sub Command1_Click()
    If IsNull(Me.txtLoginID) Then
    MsgBox "Please enter LoginID", vbInformation, "Password Required"
    Me.textLoginID.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
    MsgBox "Please enter LoginID", vbInformation, "Password Required"
    Me.textPassword.SetFocus
    Else
    If (IsNull(DLookup("[UserLogin]", "tblUser", "[UserLogin] = " & Me.txtLoginID.Value & " And
    Password = "' & Me.txtPassword.Value & '"""))) Then
    MsgBox "Incorrect LoginID and Password"
    Else
    DoCmd.Close acForm, "Login Form", acSaveYes
    DoCmd.OpenForm "Navigation Form"
    End If
    End If
    End Sub

  9. #9
    VicLetran is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    16
    The error is: compile error expected end of statement.

  10. #10
    VicLetran is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    16
    Private Sub Command1_Click()
    If IsNull(Me.txtLoginID) Then
    MsgBox "Please enter LoginID", vbInformation, "LoginID Required"
    Me.textLoginID.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
    MsgBox "Please enter password", vbInformation, "Password Required"
    Me.textPassword.SetFocus
    Else
    'process the job
    If (IsNull(DLookup("[UserLogin]", "tblUser", "[UserLogin] = " & Me.txtLoginID.Value & " And
    Password = "' & Me.txtPassword.Value & '"""))) Then
    MsgBox "Incorrect LoginID and Password"
    Else
    DoCmd.Close acForm, "Login Form", acSaveYes
    DoCmd.OpenForm "Navigation Form"
    End If
    End If
    End Sub

  11. #11
    VicLetran is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Posts
    16
    I solved my own problem. Here's the correct code that worked.

    Option Compare Database


    Private Sub Command1_Click()


    Dim UserName As String


    If IsNull(Me.txtUsername) Then
    MsgBox "Please enter LoginID", vbInformation, "LoginID Required"
    Me.txtUsername.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
    MsgBox "Please enter password", vbInformation, "Password Required"
    Me.txtPassword.SetFocus
    Else
    'process the job
    If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin = '" & Me.txtUsername.Value & "' And Password = '" & Me.txtPassword.Value & "'"))) Then
    MsgBox "Invalid username or Password"
    Else

    DoCmd.Close acForm, "Login Form", acSaveYes
    DoCmd.OpenForm "Navigation Form"
    End If
    End If
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 18
    Last Post: 12-15-2016, 02:17 PM
  2. Replies: 0
    Last Post: 03-13-2013, 08:00 AM
  3. Replies: 2
    Last Post: 03-08-2013, 12:59 PM
  4. Replies: 4
    Last Post: 07-25-2012, 04:01 AM
  5. Replies: 13
    Last Post: 12-05-2011, 05:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums