Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009

    Unanswered: VBA Field Type Issue

    I am noobie when it comes to VBA. I found a simple login example that I would like incorporate into a database. Here is the link: <<>>

    So I modified the code to fit my example as such:
    Public Sub Login()

    On Error GoTo ErrorHandler

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

    If IsNull([cboCurrentEmployee]) = True Then
    MsgBox "You must enter a User Name."

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

    ElseIf IsNull([txtPassword]) = True Then
    MsgBox "You must enter a Password."


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

    If Me.txtPassword.Value = DLookup("chrEmpPassword", "tblEmployees", "[idsEmployeeID]=" & Me.cboCurrentEmployee.Value & "'") Then
    'Set the value of strUser declares a Golbal Variable
    strUser = Me.cboCurrentEmployee.Value
    strRole = DLookup("chrRole", "tblEmployees", "[idsEmployeeID]=" & Me.cboCurrentEmployee.Value & "'") 'set the value of strRole declared as Global Variable

    'Close logon form and open splash screen

    DoCmd.Close acForm, "frmLoginDialog", acSaveNo
    MsgBox "Welcome Back, " & strUser, vbOKOnly, "Welcome"
    DoCmd.OpenForm "frmHome", acNormal, "", "", , acNormal

    MsgBox "Password Invalid. Please Try Again", vbOKOnly, _
    "Invalid Entry!"
    intLogAttempt = intLogAttempt + 1
    End If

    End If

    'If User Enters incorrect password 3 times database will shutdown

    intLogAttempt = intLogAttempt + 1
    If intLogAttempt > 3 Then
    MsgBox "You do not have access to this database.Please contact admin.", _
    vbCritical, "Restricted Access!"
    End If


    End Sub

    When I click on the Login button (which calls the Login()) it does not do anything. I was able to successfully recreate the example login but it uses the Username and that is a text type field. My database is using idsEmployeeID which is an AutoNumber type field. I am almost 99% sure it has to do with the number field. Can someone tell how I need to modifiy the above code to user idsEmployeeID. I sure this is a fairly noobie question and I apologize in advance.


  2. #2
    Join Date
    Feb 2009
    Figure it out.

    Removing the & "'" did the trick.


  3. #3
    Join Date
    Dec 2002
    Préverenges, Switzerland
    take a step or two backwards.

    slap a breakpoint on the first line "On Error GoTo ErrorHandler" (click in the left margin of the code and you get a red dot).


    what happens?
    execution stops at the breakpoint or your sub() is not being called
    if it stops F8 through the code, waving your mouse at each variable in turn as its line comes up - in principle the current variable value or expression value gets displayed. do you actually get into your sub()? and if yes, do you see what you expect to see?

    i'm off to the telly so cant look at your code in detail, but my guess is that either your sub() doesnt get called or, if it does, you screwed up the quotes in the dlookup (you have at least one unbalanced single-quote).


    PS - don't store passwords in plaintext in the db: thats far too easy for the unGodly. as a minimum store SHA1(username & password).

    Baaaaaah - you beat me to it!
    Last edited by izyrider; 12-23-11 at 14:12. Reason: too slow
    currently using SS 2008R2

Posting Permissions

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