US to UK Date format

LSTC018

Registered User.
Local time
Today, 02:14
Joined
Jan 17, 2019
Messages
19
Hi,
I’m complete beginner challenging myself, getting relevant things I want to achieve from the internet and now this forum – I’ve managed to get this VBA below to work to a point. I’ve worked out that my dates which are UK format are treated as US format giving me random results (I can see why) BUT - Can anyone help how I can change this?


_______________________________________________




Option Compare Database

Private Sub Command12_Click()
' search button
Call search
End Sub
Sub search()
Dim strCriteria, task As String

Me.Refresh
If IsNull(Me.OrderDateFrom) Or IsNull(Me.OrderDateTo) Then
MsgBox "Please enter the date range", vbInformation, "Date Range Required"
Me.OrderDateFrom.SetFocus

Else
strCriteria = "([Order Date] between #" & Me.OrderDateFrom & "# And #" & Me.OrderDateTo & "#)"
task = "Select * from Table1 where (" & strCriteria & ") order by [Order Date]"
DoCmd.ApplyFilter task

End If

End Sub
 
This will help hopefully http://allenbrowne.com/ser-36.html

You need to format your dates - I personally would format them as YYYY-MM-DD as it's really easy to read and pretty universally accepted by almost all database systems.
 
Hi,


Unfortunately all the tables I’m looking at to get reports from are already set up with DD/MM/YYYY and can't be changed,


Cheers
 
Bingo - Thats done the job I've been working on that for two days - Cheers
 
You're welcome. You will need to do this on ALL your SQL statements for the code to work reliably
 

Users who are viewing this thread

Back
Top Bottom