Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010
    Posts
    1

    Red face Unanswered: MS ACCESS VBA code Login. HELP

    hey. i adapted this code. but i'm having problem in this code.
    If Me.txtPassword.Value = DLookup("Password", "Login", "[ID_Num] =" & Me.cbo.Value) Then

    ID_Num = Me.cbo.Value
    and this is the full code.
    Private Sub Form_Open(Cancel As Integer)
    'On open set focus to combo box
    Me.cbo.SetFocus
    End Sub

    Private Sub cbo_AfterUpdate()
    'After selecting user name set focus to password field
    Me.txtPassword.SetFocus
    End Sub

    Private Sub cmdLogin_Click()

    'Check to see if data is entered into the UserName combo box

    If IsNull(Me.cbo) Or Me.cbo = "" Then
    MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
    Me.cbo.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 "You must enter a Password.", vbOKOnly, "Required Data"
    Me.txtPassword.SetFocus
    Exit Sub
    End If

    'Check value of password in tblEmployees to see if this matches value chosen in combo box

    If Me.txtPassword.Value = DLookup("Password", "Login", "[ID_Num] =" & Me.cbo.Value) Then

    ID_Num = Me.cbo.Value

    'Close logon form and open splash screen

    DoCmd.Close acForm, "Login", acSaveNo
    DoCmd.OpenForm "Mainform"

    Else
    MsgBox "Password Invalid. Please Try Again", vbOKOnly, "Invalid Entry!"
    Me.txtPassword.SetFocus
    End If


    End Sub
    i dont know whats wrong. i followed the instructions and still there an error there. i created a module that has a code "Public ID_Num As Long" but still there an error. help please.

  2. #2
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Is Me.cbo.Value null when it runs?
    Try Nz(Me.cbo.Value,0) in place of Me.cbo.Value

    The domain lookup does not like it when you try to add a null value to what is supposed to be a string parameter.
    have fun!

    Todd S.
    click to email


    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET


    _________________________________________________
    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

  3. #3
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388
    Is the combo box a drop down with a list the user names and the ID_NUM is part of the combo box?

    If so then you will need to show the column number in the "[ID_Num] = " part of the Dlookup. In your current Dlookup code you are trying using a text field to reference a number field in the Login table.

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
  •