Hi everyone, I am having this problem when trying to call a report from within vba...
pretty much what is happening, I am getting my data from sql via an ODBC connection, and I am querying that table to get the necessary parameters for my report...
When the data comes in, the dates are formatted like dd/mm/yyyy, which I think access doesnt like very much..the dates are then put into a listbox, where people can pick a date to query by. here is a screen of my form:
ok so that is how the dates are formatted. So I am trying to change the dates in my vba code so that it queries them correctly...
here is the code I have to deal with the dates:
I did originally have a BETWEEN in my sql clause instead of <=/>=, but i thought maybe that was the issue (it wasnt)...
I am running the report with:
and then this is what my criteria for my query actually ends up being
the #09/05/2010# comes from the DateAdd("d", -5, lbdate), where the second date is just lbDate. so I dont know what is happening...but when I do DateAdd, it seems to just forget about how I just formatted lbDate, and switches the format back to dd/mm/yyyy....which is lame.
anyways...hopefully someone understands what is going on..cause I dont, which makes it hard to explain..so feel free to ask me to clarify something if you dont get it
Thanks, Paul
pretty much what is happening, I am getting my data from sql via an ODBC connection, and I am querying that table to get the necessary parameters for my report...
When the data comes in, the dates are formatted like dd/mm/yyyy, which I think access doesnt like very much..the dates are then put into a listbox, where people can pick a date to query by. here is a screen of my form:

ok so that is how the dates are formatted. So I am trying to change the dates in my vba code so that it queries them correctly...
here is the code I have to deal with the dates:
Code:
If (emptyListBox = False) Then
lbdate = Me.DateListBox.Value
lbdate = Format(Month(CDate(lbdate)), "00") & "/" & Format(day(CDate(lbdate)), "00") & "/" & CStr(Year(CDate(lbdate)))
DateStr = DateStr & " [Date] >= #" & DateAdd("d", -5, lbdate) & "# AND [Date] <= #" & lbdate & "#"
End If
I am running the report with:
Code:
DoCmd.OpenReport "rei_report", acViewReport, , criteria

the #09/05/2010# comes from the DateAdd("d", -5, lbdate), where the second date is just lbDate. so I dont know what is happening...but when I do DateAdd, it seems to just forget about how I just formatted lbDate, and switches the format back to dd/mm/yyyy....which is lame.
anyways...hopefully someone understands what is going on..cause I dont, which makes it hard to explain..so feel free to ask me to clarify something if you dont get it

Thanks, Paul