Share via

DlookUp in SQL

Anonymous
2018-01-07T17:50:47+00:00

Below is a DLookUp expression I used in a access table that works perfectly. It reads from the table "tblUsers"

If Me.Password.Value = DLookup("Password", "tblUsers", "UserName='" & Me.Username.Value & "'") Then

DoCmd.OpenForm "frmNavigation", acNormal

Else

MsgBox "The password you entered is incorrect", vbOKOnly, "Login"

End If

I have since converted the table to SQL and changed the table from which the DLookUP would read from "tblUsers" to "dbo_tblUsers":

If Me.Password.Value = DLookup("Password", "dbo_tblUsers", "UserName='" & Me.Username.Value & "'") Then

DoCmd.OpenForm "frmNavigation", acNormal

Me.UserLookup.Value = (myUser)

Else

MsgBox "The password you entered is incorrect", vbOKOnly, "Login"

End If

I know that the username and password are correct but with the SQL table (dbo_tblUsers) I keep getting the message "The password you entered is incorrect", which is the 'Else' message from the If statement"

How I I fix this?

Thanks for any help I can get

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

Answer accepted by question author

Anonymous
2018-01-10T15:57:43+00:00

Thanks for all the assistance. I found a work around. It seems like the field in SQL is been evaluated as something else in MS access. I used DLookUp to evaluate the Username and Password as a number (ID) and then do a match so that what was entered matched the database. I will have to use this until I can come up with a more efficient method.

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. ScottGem 68,830 Reputation points Volunteer Moderator
    2018-01-07T19:22:33+00:00

    Hmm. Have you stepped through the code and confirmed the value of Me.Username? And the value the DLookup returns?

    The code looks correct, but if its choosing the Else clause, then the value the DLookup is returning is not matching what was typed.

    My login routine doesn't work the way your does. You can see how I do it at https://scottgem.wordpress.com/?s=login. Basically, I use a combobox for the user to select themselves. The combo returns the user's ID (an autonumber field). The password is also part of the Rowsource so I compare to the column in the rowsource, instead of using a DLookup (DLookups are usually my last resort).

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2018-01-07T18:48:01+00:00

    Thanks for your quick reply. I have done all that and have conducted tests that shows that the DLookUP works on the same form from the same table "dbo_tblUsers"

    Was this answer helpful?

    0 comments No comments
  3. ScottGem 68,830 Reputation points Volunteer Moderator
    2018-01-07T18:35:50+00:00

    So you migrated your data to SQL Server? You relinked your front end to the correct SQL Server back end? Can you open dbo_tblUsers from the Navigation Pane?

    Have you tried testing the DLookup in Immediate mode?

    Was this answer helpful?

    0 comments No comments