By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,469 Members | 2,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,469 IT Pros & Developers. It's quick & easy.

dlookup not working

P: 7
hi, whats wrong with this code?
Expand|Select|Wrap|Line Numbers
  1.  If Me.txtPassword.Value = DLookup("[User_Password]", "User", "[User_Name]='" & Me.txtUsername.Value & "'") Then
  2.     DoCmd.OpenForm "frmDetails"
  3. Else
  4.     MsgBox "Wrong Log In details!", vbCritical, "Warning"
  5.     Me.txtUsername.SetFocus
  6. End If
  7.  
  8.  
it always highlights the dlookup line whenever i cluck the the login command
Jan 7 '08 #1
Share this Question
Share on Google+
4 Replies


missinglinq
Expert 2.5K+
P: 3,532
I set up a clone of your User table and form with all controls/fields named the same and the code runs perfectly! My first thought would be to double check the spelling of the names of all objects, including the table name. User instead of Users would be all it'd take to break the code, as well as the name of any control/field involved. My only other thought would be corruption of your form, with seems unlikely, given the utter simplicity of it!

Welcome to TheScripts!

Linq ;0)>
Jan 7 '08 #2

P: 7
I set up a clone of your User table and form with all controls/fields named the same and the code runs perfectly! My first thought would be to double check the spelling of the names of all objects, including the table name. User instead of Users would be all it'd take to break the code, as well as the name of any control/field involved. My only other thought would be corruption of your form, with seems unlikely, given the utter simplicity of it!

Welcome to TheScripts!

Linq ;0)>
thanks! found the problem my record source is empty, so i use the record to table User, am i doing the right thig here?
Jan 7 '08 #3

missinglinq
Expert 2.5K+
P: 3,532
Which record source is empty? User table or the table behind frmDetails?

And I'm sorry, but I don't understand "i use the record to table User."

Linq ;0)>
Jan 7 '08 #4

Minion
Expert 100+
P: 108
I'm not sure I understand either what you mean by using the table to User, but if you're having problems with the recordsource being empty (ie. getting an error that the Dlookup is null) then you might want to change your code to the following:

Expand|Select|Wrap|Line Numbers
  1. If Me.txtPassword.Value = Nz(DLookup("[User_Password]", "User", "[User_Name]='" & Me.txtUsername.Value & "'") , 0) Then
  2.     DoCmd.OpenForm "frmDetails"
  3. Else
  4.     MsgBox "Wrong Log In details!", vbCritical, "Warning"
  5.     Me.txtUsername.SetFocus
  6. End If
  7.  
This should return a "0" instead of the Null value and save you an error. On a whole I have found that you should just about always trap for Null when using DLookup to avoid errors.

Hope this helps.

- Minion -
Jan 7 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.