DLookup Expression

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

DLookup Expression

Post by burrina »

My code tells me that my answer is wrong, but it is right, so the code is wrong
tblanswers
answer
Is where the answer comes from. My DLookup is wrong!

Code: Select all

If IsNull(DLookup("[UserID]", "tblUserSecurity_Sec", "[UserID]='" & Me.UserID.Value & "' And [answer]='" & Me.answer.Value & "'")) Then

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DLookup Expression

Post by HansV »

Do you get an error message? If so, what does it say?
Or do you get an incorrect/unexpected result?
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: DLookup Expression

Post by burrina »

Your user name and answer do not match

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: DLookup Expression

Post by burrina »

This is the query result, it is correct.
You do not have the required permissions to view the files attached to this post.

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: DLookup Expression

Post by burrina »

txtyouranswer = answer need to match
txtyouranswer is unbound answer is bound

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DLookup Expression

Post by HansV »

tblUserSecurity_Sec has fields userID and pw, not userID and answer.
answer is a field in tblquestions, not in tblUserSecurity_Sec.
The text box in which the answer is entered is txtyouranswer.
So:

Code: Select all

If IsNull(DLookup("[UserID]", "tblUserSecurity_Sec", "[UserID]='" & Me.userID.Value & "' And [pw]='" & Me.txtyouranswer.Value & "'")) Then
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: DLookup Expression

Post by burrina »

I hope this explains it better. I have made changes, record source, everything with no luck.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: DLookup Expression

Post by HansV »

That requires a completely different approach: the form should be unbound, and you need to build in lots of checks.
I have sent you an email.
Best wishes,
Hans

User avatar
burrina
4StarLounger
Posts: 550
Joined: 30 Jul 2014, 23:58

Re: DLookup Expression

Post by burrina »

Many thanks. Works just fine.