I wonder if someone can help. I have two unbound date columns Date From and Date To. A macro on the form works perfectly!!!! the ‘where’ statement shows:
[PurchaseDate]>=[Forms]![GeneralDateEntry]![DateFrom] And [PurchaseDate]<=[Forms]![GeneralDateEntry]![DateTo]
However, due to the amount of where statements – i am trying to amalgamate them into a VB string. All strings work - but not the dates....
---
If Not IsNull(Me.DateFrom) And Me.PurchasedTick = -1 Then
strWhere = strWhere & " AND [PurchaseDate] >= " & [Forms]![GeneralDateEntry]![DateFrom]
End If
If Not IsNull(Me.DateTo) And Me.PurchasedTick = -1 Then
strWhere = strWhere & " AND [PurchaseDate] <= " & [Forms]![GeneralDateEntry]![DateTo]
End If
DoCmd.OpenReport stDocument, acPreview, , strWhere
---
I put in dates from 01/10/2010 to 05/10/2010
It outputs everything from 10th Jan – 10th May! Swapping the month and day around.
I output a contents of strWhere just before calling the report – and it shows PurchaseDate>=#01/10/2010# And PurchaseDate<=#10/01/2010#
The dates are text fields formatted showing yearmonthday. In query :
PurchaseDate: CDate(DateSerial(Left([vehicles]![PurchaseDate],4),Mid([vehicles]![PurchaseDate],5,2),Right([vehicles]![PurchaseDate],2)))
I’m Confused ...especially as it works on the macro....any help very welcome.
Thanks
Mary