#error using dlookup

R

raviyah

I have a dlookup in a text box on a form.
=DLookUp("username","tbluser","userid= " & [txtuserid]))

If there is a value in txtuser then the dlookup works fine. if not, I get an
#error in the text box. i have tried iif(..) but can't get the message to go
away.
 
S

Stuart McCall

raviyah said:
I have a dlookup in a text box on a form.
=DLookUp("username","tbluser","userid= " & [txtuserid]))

If there is a value in txtuser then the dlookup works fine. if not, I get
an
#error in the text box. i have tried iif(..) but can't get the message to
go
away.

Try using the Nz function ('Null to Zero'), like this:

=DLookUp("username","tbluser","userid= " & Nz([txtuserid])))
 
R

raviyah

still get #error message

Stuart McCall said:
raviyah said:
I have a dlookup in a text box on a form.
=DLookUp("username","tbluser","userid= " & [txtuserid]))

If there is a value in txtuser then the dlookup works fine. if not, I get
an
#error in the text box. i have tried iif(..) but can't get the message to
go
away.

Try using the Nz function ('Null to Zero'), like this:

=DLookUp("username","tbluser","userid= " & Nz([txtuserid])))
 
R

raviyah

Using the valueifnull argument solved the problem. Thank you

Mike Painter said:
raviyah said:
still get #error message

Stuart McCall said:
I have a dlookup in a text box on a form.
=DLookUp("username","tbluser","userid= " & [txtuserid]))

If there is a value in txtuser then the dlookup works fine. if not,
I get an
#error in the text box. i have tried iif(..) but can't get the
message to go
away.

Try using the Nz function ('Null to Zero'), like this:

=DLookUp("username","tbluser","userid= " & Nz([txtuserid])))

Text fields must be delimited in quotes.
Also is txtuserid the name of the textbox or a field name?

DLookUp("username","tbluser","userid= '" & Nz([me.txtuserid],"") & "' )"

That's single quote double quote after the equal sign and double quote
single quote before the ")"
You also had three ")" where there should be two.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top