PC Review


Reply
Thread Tools Rate Thread

Dlookup only returning the first record

 
 
Don Barton
Guest
Posts: n/a
 
      13th Jan 2011
Access 2007. Unbound form with Username and Password controls and cmd
button with VBA behind the OnClick event.
My criteria is being ignored in my DLookup expression.
UName = DLookup("[StudUName]", "tblStudentAccess", "StudPW = '" &
Me.password & "'")
UName is Dimmed as variant (tried String as well)
Me.Password.value criteria is correctly read off the unbound form
password control.
Student Username (StudUName) returned is from the first record -which
is a different password.
It is as if the criteria is being ignored.
The result is UName returns a null, so the error routine kicks in.
I've never seen this before. Is my criteria syntax wrong? password is
a String
Any ideas?

Don
 
Reply With Quote
 
 
 
 
Rick Brandt
Guest
Posts: n/a
 
      13th Jan 2011
Don Barton wrote:

> Access 2007. Unbound form with Username and Password controls and cmd
> button with VBA behind the OnClick event.
> My criteria is being ignored in my DLookup expression.
> UName = DLookup("[StudUName]", "tblStudentAccess", "StudPW = '" &
> Me.password & "'")
> UName is Dimmed as variant (tried String as well)
> Me.Password.value criteria is correctly read off the unbound form
> password control.
> Student Username (StudUName) returned is from the first record -which
> is a different password.
> It is as if the criteria is being ignored.
> The result is UName returns a null, so the error routine kicks in.
> I've never seen this before. Is my criteria syntax wrong? password is
> a String
> Any ideas?
>
> Don


If it is returning the first record then why would UName end up as Null?
That would be the result of DLookup() not finding a record at all which
would suggest that your criteria is being interpreted differently than you
think.

Try it with a hard-coded criteria to see if that works. You don't need the
brackets around your field name so I would try it without those as well.

 
Reply With Quote
 
Don Barton
Guest
Posts: n/a
 
      13th Jan 2011
> If it is returning the first record then why would UName end up as Null? *
> That would be the result of DLookup() not finding a record at all which
> would suggest that your criteria is being interpreted differently than you
> think.
>
> Try it with a hard-coded criteria to see if that works. *You don't needthe
> brackets around your field name so I would try it without those as well.-Hide quoted text -
>
> - Show quoted text -


I've worked on this some and have found an interesting situation.

The following code works:

strTest = Forms!frmTest!password
vartest6 = DLookup("LabTestName", "tblLabTests", "LabTestMnemonic = '"
& strTest & "' ")

When the unbound control's contents is read into a variable, and this
is used as a criteria, varTest6 give a correct vaule.

But when I try reading the unbound control directly from the form as
my criteria, I get an error.
"The expression you entered as a query parameter produced this error:
[string in unbound control]"
vartest5 = DLookup("LabTestName", "tblLabTests", "LabTestMnemonic = "
& Forms!frmTest!password)

Shouldn't either of these DLookup scenarios work??

Thanks



 
Reply With Quote
 
Rick Brandt
Guest
Posts: n/a
 
      13th Jan 2011
Don Barton wrote:

>> If it is returning the first record then why would UName end up as Null?
>> That would be the result of DLookup() not finding a record at all which
>> would suggest that your criteria is being interpreted differently than
>> you think.
>>
>> Try it with a hard-coded criteria to see if that works. You don't need
>> the brackets around your field name so I would try it without those as
>> well.- Hide quoted text -
>>
>> - Show quoted text -

>
> I've worked on this some and have found an interesting situation.
>
> The following code works:
>
> strTest = Forms!frmTest!password
> vartest6 = DLookup("LabTestName", "tblLabTests", "LabTestMnemonic = '"
> & strTest & "' ")
>
> When the unbound control's contents is read into a variable, and this
> is used as a criteria, varTest6 give a correct vaule.
>
> But when I try reading the unbound control directly from the form as
> my criteria, I get an error.
> "The expression you entered as a query parameter produced this error:
> [string in unbound control]"
> vartest5 = DLookup("LabTestName", "tblLabTests", "LabTestMnemonic = "
> & Forms!frmTest!password)
>
> Shouldn't either of these DLookup scenarios work??


Your second one doesn't surround the value with quotes. Those are required
if it's a string.

 
Reply With Quote
 
Don Barton
Guest
Posts: n/a
 
      14th Jan 2011
On Jan 13, 6:35*pm, Rick Brandt <rickbran...@hotmail.com> wrote:
> Don Barton wrote:
> >> If it is returning the first record then why would UName end up as Null?
> >> That would be the result of DLookup() not finding a record at all which
> >> would suggest that your criteria is being interpreted differently than
> >> you think.

>
> >> Try it with a hard-coded criteria to see if that works. *You don't need
> >> the brackets around your field name so I would try it without those as
> >> well.- Hide quoted text -

>
> >> - Show quoted text -

>
> > I've worked on this some and have found an interesting situation.

>
> > The following code works:

>
> > strTest = Forms!frmTest!password
> > vartest6 = DLookup("LabTestName", "tblLabTests", "LabTestMnemonic ='"
> > & strTest & "' ")

>
> > When the unbound control's contents is read into a variable, and this
> > is used as a criteria, varTest6 give a correct vaule.

>
> > But when I try reading the unbound control directly from the form as
> > my criteria, I get an error.
> > "The expression you entered as a query parameter produced this error:
> > [string in unbound control]"
> > vartest5 = DLookup("LabTestName", "tblLabTests", "LabTestMnemonic ="
> > & Forms!frmTest!password)

>
> > Shouldn't either of these DLookup scenarios work??

>
> Your second one doesn't surround the value with quotes. *Those are required
> if it's a string.


Thanks Rick, that makes sense. The MS examples showed no quote, but
that must have been because of they were numeric.
Don
 
Reply With Quote
 
Don Barton
Guest
Posts: n/a
 
      14th Jan 2011
On Jan 13, 6:35*pm, Rick Brandt <rickbran...@hotmail.com> wrote:
> Don Barton wrote:
> >> If it is returning the first record then why would UName end up as Null?
> >> That would be the result of DLookup() not finding a record at all which
> >> would suggest that your criteria is being interpreted differently than
> >> you think.

>
> >> Try it with a hard-coded criteria to see if that works. *You don't need
> >> the brackets around your field name so I would try it without those as
> >> well.- Hide quoted text -

>
> >> - Show quoted text -

>
> > I've worked on this some and have found an interesting situation.

>
> > The following code works:

>
> > strTest = Forms!frmTest!password
> > vartest6 = DLookup("LabTestName", "tblLabTests", "LabTestMnemonic ='"
> > & strTest & "' ")

>
> > When the unbound control's contents is read into a variable, and this
> > is used as a criteria, varTest6 give a correct vaule.

>
> > But when I try reading the unbound control directly from the form as
> > my criteria, I get an error.
> > "The expression you entered as a query parameter produced this error:
> > [string in unbound control]"
> > vartest5 = DLookup("LabTestName", "tblLabTests", "LabTestMnemonic ="
> > & Forms!frmTest!password)

>
> > Shouldn't either of these DLookup scenarios work??

>
> Your second one doesn't surround the value with quotes. *Those are required
> if it's a string.


Thanks Rick. That makes sense. The examples I looked at didn't have
any quotes, which means they must have been addressing numeric values.
Moving forward,
Don
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DLookUp Returning Primary Key channell Microsoft Access 4 18th Jan 2009 01:51 AM
Re: DLookUp Returning Primary Key RoyVidar Microsoft Access 0 15th Jan 2009 04:18 PM
Returning to previous record (if exists) instead of returning to the first record in a form after requery Amir Microsoft Access Form Coding 6 1st Mar 2006 04:46 PM
Dlookup returning null =?Utf-8?B?S2FybCBI?= Microsoft Access VBA Modules 1 21st Jan 2006 03:37 PM
DLOOKUP returning error garethg Microsoft Access Forms 1 4th Mar 2004 08:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:43 PM.