K
Kagsy
Dear Guys
I am now officially at my wit's end, so I really need your
guy’s help.
I am using VBA to find a record in table by a date field.
Sounds straightforward, but VBA converts the date variable
to the US format and the date in my table is in UK format
(it finds by "mm/dd/yy" rather than "dd/mm/yy"). Because
the format is different the record is not found.
I then changed the date to #01/April/2004# which was then
changed to #04/01/2004# but when I tried to use the
dateadd function the date became #05/01/04#, which is
correct but I am now searching for 1st May rather than the
2nd April.
How can I declare variables called startDate and curDate
that is set to #01/April/2004# with the EndDate of
#23/June/2004# and tries to find a record in a table (set
to UK date format - code for searching not needed) with a
UK date and also when I add a day with the DateAdd
function to curDate, the value becomes #02/04/2004#?
If I keep the startDate variable to #1/4/04#, this is
changed to the US format and the record is found but the
DataAdd function adds 1 day in US format to become
#05/01/2004# which is the 1st May not the 2nd of April as
I would like.
Where do I go from here? I would like to thank all those
who have read the post through the end and not died of old
age or boredom.
Thanks again.
Kagsy.
This code snipet may help:
Private Sub FindRecord()
Dim StartDate As Date
Dim endDate As Date
Dim curDate As Date
StartDate = #1/4/2004#
endDate = Date - 1
curDate = #1/4/2004#
do until rs.eof
'Function to find record for that date
curDate = DateAdd("d", 1, curDate)
Loop
End Sub
I am now officially at my wit's end, so I really need your
guy’s help.
I am using VBA to find a record in table by a date field.
Sounds straightforward, but VBA converts the date variable
to the US format and the date in my table is in UK format
(it finds by "mm/dd/yy" rather than "dd/mm/yy"). Because
the format is different the record is not found.
I then changed the date to #01/April/2004# which was then
changed to #04/01/2004# but when I tried to use the
dateadd function the date became #05/01/04#, which is
correct but I am now searching for 1st May rather than the
2nd April.
How can I declare variables called startDate and curDate
that is set to #01/April/2004# with the EndDate of
#23/June/2004# and tries to find a record in a table (set
to UK date format - code for searching not needed) with a
UK date and also when I add a day with the DateAdd
function to curDate, the value becomes #02/04/2004#?
If I keep the startDate variable to #1/4/04#, this is
changed to the US format and the record is found but the
DataAdd function adds 1 day in US format to become
#05/01/2004# which is the 1st May not the 2nd of April as
I would like.
Where do I go from here? I would like to thank all those
who have read the post through the end and not died of old
age or boredom.
Thanks again.
Kagsy.
This code snipet may help:
Private Sub FindRecord()
Dim StartDate As Date
Dim endDate As Date
Dim curDate As Date
StartDate = #1/4/2004#
endDate = Date - 1
curDate = #1/4/2004#
do until rs.eof
'Function to find record for that date
curDate = DateAdd("d", 1, curDate)
Loop
End Sub