DLookup Date

  • Thread starter gmazza via AccessMonster.com
  • Start date
G

gmazza via AccessMonster.com

Hey there,
I am trying to do a DLookup on a Date field.
Do I declare the result as a date?
Dim Result as Date

This keeps returning 12:00:00 AM
answer = DLookup("VisitDate", "PatientData", "VisitDate = '" & Me.VisitDate &
"'")
 
K

Klatuu

You are passing VisitDate as a string. It needs to be passed as a Date:
answer = DLookup("VisitDate", "PatientData", "VisitDate = #" & Me.VisitDate &
 
G

gmazza via AccessMonster.com

I am still getting a result of 12:00:00 AM with the following:

answer = DLookup("VisitDate", "PatientData", "VisitDate = #" & Me.VisitDate &
"#")

You are passing VisitDate as a string. It needs to be passed as a Date:
answer = DLookup("VisitDate", "PatientData", "VisitDate = #" & Me.VisitDate &
Hey there,
I am trying to do a DLookup on a Date field.
[quoted text clipped - 4 lines]
answer = DLookup("VisitDate", "PatientData", "VisitDate = '" & Me.VisitDate &
"'")
 
K

Klatuu

What is the value of Me.VisitDate?
Do your field values have time in them?

--
Dave Hargis, Microsoft Access MVP


gmazza via AccessMonster.com said:
I am still getting a result of 12:00:00 AM with the following:

answer = DLookup("VisitDate", "PatientData", "VisitDate = #" & Me.VisitDate &
"#")

You are passing VisitDate as a string. It needs to be passed as a Date:
answer = DLookup("VisitDate", "PatientData", "VisitDate = #" & Me.VisitDate &
Hey there,
I am trying to do a DLookup on a Date field.
[quoted text clipped - 4 lines]
answer = DLookup("VisitDate", "PatientData", "VisitDate = '" & Me.VisitDate &
"'")
 
D

Douglas J. Steele

Also, what's your Short Date format? If it's not mm/dd/yyyy, you need to use

answer = DLookup("VisitDate", "PatientData", "VisitDate = " &
Format(Me.VisitDate, "\#yyyy\-mm\-dd\#")

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Klatuu said:
What is the value of Me.VisitDate?
Do your field values have time in them?

--
Dave Hargis, Microsoft Access MVP


gmazza via AccessMonster.com said:
I am still getting a result of 12:00:00 AM with the following:

answer = DLookup("VisitDate", "PatientData", "VisitDate = #" &
Me.VisitDate &
"#")

You are passing VisitDate as a string. It needs to be passed as a Date:
answer = DLookup("VisitDate", "PatientData", "VisitDate = #" &
Me.VisitDate &
"#")

Hey there,
I am trying to do a DLookup on a Date field.
[quoted text clipped - 4 lines]
answer = DLookup("VisitDate", "PatientData", "VisitDate = '" &
Me.VisitDate &
"'")
 
G

gmazza via AccessMonster.com

The value of Me.VisitDate is 10/07/2009.
I entered it on the form as 10/Jul/09.
I don't believe my fields have time.
What is the value of Me.VisitDate?
Do your field values have time in them?
I am still getting a result of 12:00:00 AM with the following:
[quoted text clipped - 10 lines]
 
G

gmazza via AccessMonster.com

I don't know what my date format is at all.
I tied that statement and received a syntax error.
Also, what's your Short Date format? If it's not mm/dd/yyyy, you need to use

answer = DLookup("VisitDate", "PatientData", "VisitDate = " &
Format(Me.VisitDate, "\#yyyy\-mm\-dd\#")
What is the value of Me.VisitDate?
Do your field values have time in them?
[quoted text clipped - 16 lines]
 
D

Douglas J. Steele

If you're saying that 10/07/2009 represents 0/Jul/09, then your Short Date
format likely is dd/mm/yyyy.

There was a typo in my previous response: I was missing a closing
parenthesis:

answer = DLookup("VisitDate", "PatientData", "VisitDate = " &
Format(Me.VisitDate, "\#yyyy\-mm\-dd\#"))

Sorry about that...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


gmazza via AccessMonster.com said:
I don't know what my date format is at all.
I tied that statement and received a syntax error.
Also, what's your Short Date format? If it's not mm/dd/yyyy, you need to
use

answer = DLookup("VisitDate", "PatientData", "VisitDate = " &
Format(Me.VisitDate, "\#yyyy\-mm\-dd\#")
What is the value of Me.VisitDate?
Do your field values have time in them?
[quoted text clipped - 16 lines]
Me.VisitDate &
"'")
 
G

gmazza via AccessMonster.com

Sorry, shoulda caught that parenthesis. No syntax error, but still getting
the same result:
12:00:00 AM
The error is saying Invalid use of a Null.
If you're saying that 10/07/2009 represents 0/Jul/09, then your Short Date
format likely is dd/mm/yyyy.

There was a typo in my previous response: I was missing a closing
parenthesis:

answer = DLookup("VisitDate", "PatientData", "VisitDate = " &
Format(Me.VisitDate, "\#yyyy\-mm\-dd\#"))

Sorry about that...
I don't know what my date format is at all.
I tied that statement and received a syntax error.
[quoted text clipped - 10 lines]
 
K

Klatuu

Doug has you on the right track.
--
Dave Hargis, Microsoft Access MVP


gmazza via AccessMonster.com said:
The value of Me.VisitDate is 10/07/2009.
I entered it on the form as 10/Jul/09.
I don't believe my fields have time.
What is the value of Me.VisitDate?
Do your field values have time in them?
I am still getting a result of 12:00:00 AM with the following:
[quoted text clipped - 10 lines]
answer = DLookup("VisitDate", "PatientData", "VisitDate = '" & Me.VisitDate &
"'")
 
D

Douglas J. Steele

Does your VisitDate field in your table include time, or is it strictly a
date value? Does the control VisitDate on your form have a value in it?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


gmazza via AccessMonster.com said:
Sorry, shoulda caught that parenthesis. No syntax error, but still getting
the same result:
12:00:00 AM
The error is saying Invalid use of a Null.
If you're saying that 10/07/2009 represents 0/Jul/09, then your Short Date
format likely is dd/mm/yyyy.

There was a typo in my previous response: I was missing a closing
parenthesis:

answer = DLookup("VisitDate", "PatientData", "VisitDate = " &
Format(Me.VisitDate, "\#yyyy\-mm\-dd\#"))

Sorry about that...
I don't know what my date format is at all.
I tied that statement and received a syntax error.
[quoted text clipped - 10 lines]
Me.VisitDate &
"'")
 
D

Douglas J. Steele

You haven't answered the questions I asked:

Does your VisitDate field in your table include time, or is it strictly a
date value? Does the control VisitDate on your form have a value in it?
 
G

gmazza via AccessMonster.com

Sorry, I answered the time question that Klatuu asked a little above.
No it does not include time. Its just a date/time field with no format.
Yes, the control VisitDate has a value of 10/Jul/09.
 
D

Douglas J. Steele

See whether this makes any difference:

answer = DLookup("VisitDate", "PatientData", "VisitDate = " &
Format(CDate(Me.VisitDate), "\#yyyy\-mm\-dd\#"))
 
G

gmazza via AccessMonster.com

Same thing. Its really weird, I must be doing something wrong??
See whether this makes any difference:

answer = DLookup("VisitDate", "PatientData", "VisitDate = " &
Format(CDate(Me.VisitDate), "\#yyyy\-mm\-dd\#"))
Sorry, I answered the time question that Klatuu asked a little above.
No it does not include time. Its just a date/time field with no format.
[quoted text clipped - 10 lines]
 
D

Douglas J. Steele

Hold on. VisitDate is a field in the form's underlying recordset, correct?
If it's also the name of the text box to which that field is bound, you may
need to rename the text box (say, to txtVisitDate), and use Me.txtVisitDate
in your lookup.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


gmazza via AccessMonster.com said:
Same thing. Its really weird, I must be doing something wrong??
See whether this makes any difference:

answer = DLookup("VisitDate", "PatientData", "VisitDate = " &
Format(CDate(Me.VisitDate), "\#yyyy\-mm\-dd\#"))
Sorry, I answered the time question that Klatuu asked a little above.
No it does not include time. Its just a date/time field with no format.
[quoted text clipped - 10 lines]
I'll make you a citizen of the world yet, Dave! <g>
 

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