Results 1 to 7 of 7
  1. #1
    need_help12 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    58

    Restricted Access Login Code Error

    Good afternoon.



    I searched the forum for assistance in creating a user login form for db access. I came acrosss this VB code which is partially working, but I'm experiencing an error when the password is entered. If the incorrect password is entered, I get the prompt box I've coded. If the correct password is entered, I get a "run-time error '3164' Field cannot be updated" error.

    If anyone's willing to assist, here's the code that I've enters for this. I've bold/underlined/italicized the portion creating the error.

    Private Sub Command37_Click()

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

    If IsNull(Me.Combo17) Or Me.Combo17 = "" Then
    MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
    Me.Combo17.SetFocus
    Exit Sub
    End If

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

    If IsNull(Me.Text31) Or Me.Text31 = "" Then
    MsgBox "You must enter a valid Password.", vbOKOnly, "Required Data"
    Me.Text31.SetFocus
    Exit Sub
    End If

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

    If Me.Text31.Value = DLookup("Password", "tblLogin", _
    "[ID]=" & Me.Combo17.Value) Then

    ID = Me.Combo17.Value

    'Close logon form and open navigation screen

    DoCmd.Close acForm, "frmLogin", acSaveNo
    DoCmd.OpenForm "frmNavigation"

    Else
    MsgBox "Password Invalid. Please try again.", vbOKOnly, _
    "Invalid Entry"
    Me.Text31.SetFocus
    End If

    'If User Enters incorrect password 3 times database wil shutdown

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

    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Does your form have a RecordSource and is it updateable?

  3. #3
    need_help12 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    58
    Yes sir, the Record source for my For a is a table (tblLogin) which contains username and password fields.

  4. #4
    need_help12 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    58
    Messed with it this morning, able to fix it. Thanks!

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Great to hear you got it sorted. Care to share what you did to fix it with others that read this forum?

  6. #6
    need_help12 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    58
    Sure, I changed the code from ID = Me.Combo17.Value to MyEmpID = Me.combo17.Value and then created a module which states "Public MyEmpID As Long" and that fixed it.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Thank you.

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

Similar Threads

  1. HELP>Access 2010 User Login Form Code.
    By zaaimanm in forum Programming
    Replies: 5
    Last Post: 10-22-2012, 07:28 PM
  2. Replies: 1
    Last Post: 08-10-2011, 12:04 AM
  3. Login ID Code for Access 2007 not working
    By amangupts in forum Programming
    Replies: 25
    Last Post: 07-07-2011, 01:28 PM
  4. Login Form Code
    By paddon in forum Programming
    Replies: 4
    Last Post: 04-08-2011, 06:48 PM
  5. Login/Password Code not working
    By eww in forum Programming
    Replies: 3
    Last Post: 09-21-2010, 10:49 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