Once again I have run into a Date Format issue. USA to Australian format. Filter form between two dates.
Following along with the course I entered the VB code exactly like the lesson and found it did not work accurately. No matter how I tried to format it, it would not filter properly.
I changed my Regional settings to the US format and the code works perfectly. (As per the code below) It does not work in DD/MM/YYYY or the YYYY/MM/DD Regional format either way, or under my Australian Regional settings.
I can not get my head around the fact that the codes can be affected by the Regional settings as much as it is. I am wondering what it is that I need to change to make this code match that of the Australian Regional settings?
In this lesson this code was built to be used more than one call for code hence the Private Sub "DoSearch ()"
Private Sub DoSearch()
Me.RecordSource = "SELECT * FROM CustomerT WHERE " & _ "CustomerSince >= #" & BeginDate & "# AND " & _ "CustomerSince <= #" & EndDate & "#"
End Sub
This then highlights an major problem if designing a data base to work in two different countries that uses two different Regional formats. As mentioned the agreed YYYY/MM/DD format does not work in this case.
Please could someone give me the VB code, for learning purposes, that I would need to use if programing this to accommodate our regional settings?
If I had to work around this, I would simply do this via a Query and not use the code at all. But while I know what to do in a query, I am here to learn VB.
Kevin Robertson
@Reply 4 years ago
Format the dates to the US format.
Me.RecordSource = "SELECT * FROM CustomerT WHERE " & _
"CustomerSince >= #" & Format(BeginDate, "mm/dd/yyyy") & "# AND " & _
"CustomerSince <= #" & Format(EndDate, "mm/dd/yyyy") & "#"
Allan McConnellOP
@Reply 4 years ago
Thank you Kevin. Very much appreciated.
Certainly works when set to the US format.
So this something that I will need to program into my mind for future coding.
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Access Developer 13.