Share via

Access VBA: Runtime error 2471

Anonymous
2016-05-14T14:25:16+00:00

I've copied some code to create a login form for my Access, but I keep getting this error every time I try to run the login form. It pulls the UserID from a table called Users.

Here is my code: VBACode

Below is a sceenshot of the error.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2016-05-14T15:05:09+00:00

    Are you sure the DLookup is correct:

    1. If Me.txtPassword.Value = DLookup("Password", "Users", _
    2. "[Users]=" & Me.cboUser.Value) Then

    If "Users" is a Column in the Users table, then you might be okay with that syntax. However, if the name of that column is "User" then you'd need to change that to reflect the correct name.

    Also, if that column is a Text field the DLookup should probably look like this:

    Nz(DLookup("Password", "Users", "User='" & Me.cboUser & "'"),"")

    That would return either (a) the Password, if it's found by that User or (b) a Zero Length String, if the password is not found. Either way, you'd compare it to the password entered by the user.

    I do agree with Tom that words such as "User" should not be used when programming.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. ScottGem 68,830 Reputation points Volunteer Moderator
    2016-05-14T15:26:15+00:00

    You might want to check out my blog on Login Security with VBA

    Was this answer helpful?

    0 comments No comments
  3. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2016-05-14T14:36:58+00:00

    User is a Reserved Word. Don't use it for field name or table name.

    Was this answer helpful?

    0 comments No comments