Look for date data in field

K

Ken Ivins

I want to look to a table and see if there is a specific date in that field.
If there is then do one thing and if not do another.

I did a dlookup (trying to get a null value or string value) and got an
error that the data type did not match. I saw another post that the date
need to be formated but when I tried to do that I got errors on that as
well.

varX = DLookup("biLstNam", "[tblBilling]", "biDate='" & Me.txbBillingDate &
"'")

What am I doing wrong or is there a better way to do this?


Thanks,
Ken
 
J

John Spencer (MVP)

varX = DLookup("biLstNam", "[tblBilling]",
"biDate=#" & Me.txbBillingDate & "#")

Dates are delimited with # characters. Also, Access expects date strings to be
in mm/dd/yyyy format.

Another way to do this:
varX = DLookup("biLstNam", "[tblBilling]",
"biDate=" & Format(Me.txbBillingDate,"\#mm\/dd\/yyyy\#"))
 
K

Ken Ivins

John,

I had seen the second solution and had trouble with that as well. But your
first solution worked fine and did what I needed

Thanks for your help,
Ken

John Spencer (MVP) said:
varX = DLookup("biLstNam", "[tblBilling]",
"biDate=#" & Me.txbBillingDate & "#")

Dates are delimited with # characters. Also, Access expects date strings to be
in mm/dd/yyyy format.

Another way to do this:
varX = DLookup("biLstNam", "[tblBilling]",
"biDate=" & Format(Me.txbBillingDate,"\#mm\/dd\/yyyy\#"))

Ken said:
I want to look to a table and see if there is a specific date in that field.
If there is then do one thing and if not do another.

I did a dlookup (trying to get a null value or string value) and got an
error that the data type did not match. I saw another post that the date
need to be formated but when I tried to do that I got errors on that as
well.

varX = DLookup("biLstNam", "[tblBilling]", "biDate='" & Me.txbBillingDate &
"'")

What am I doing wrong or is there a better way to do this?

Thanks,
Ken
 

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