I'm trying to open a report using a date field taken from a form to build the sqltxt. The date on the form and in the table is in UK format (dd/mm/yyyy). I have read that access, when in vba, reads it in US format (mm/dd/yyyy). What can I do to the function below to convert the date from UK to US for the code and then Back to UK for the displayed report?
Private Sub Report_Open(Cancel As Integer)
Dim db As Database
Dim rec As Recordset
Dim ReportDate As Date
Dim sqlTxt As String
Set db = CurrentDb
ReportDate = [Forms]![MainEntryForm]![Duty_Date] - ([Forms]![MainEntryForm]![DutyCycle] - 1)
sqlTxt = "SELECT * FROM Duties "
sqlTxt = sqlTxt & "WHERE Duties.Duty_Date >= #" & ReportDate & "# "
sqlTxt = sqlTxt & "AND Duties.Duty_Date <= (#" & ReportDate & "# + 7) "
sqlTxt = sqlTxt & "Order By Duties.Duty_Date;"
Set rec = db.OpenRecordset("Duties", sqlTxt)
Do While Not rec.EOF
'Do things
rec.MoveNext
Loop
rec.Close
End Sub
Private Sub Report_Open(Cancel As Integer)
Dim db As Database
Dim rec As Recordset
Dim ReportDate As Date
Dim sqlTxt As String
Set db = CurrentDb
ReportDate = [Forms]![MainEntryForm]![Duty_Date] - ([Forms]![MainEntryForm]![DutyCycle] - 1)
sqlTxt = "SELECT * FROM Duties "
sqlTxt = sqlTxt & "WHERE Duties.Duty_Date >= #" & ReportDate & "# "
sqlTxt = sqlTxt & "AND Duties.Duty_Date <= (#" & ReportDate & "# + 7) "
sqlTxt = sqlTxt & "Order By Duties.Duty_Date;"
Set rec = db.OpenRecordset("Duties", sqlTxt)
Do While Not rec.EOF
'Do things
rec.MoveNext
Loop
rec.Close
End Sub