This problem has plagued me for years and search as I might, I haven't come up with the perfect solution. I'm in Canada and work for clients in the US, the UK etc. While I'm not a programmer, sometimes, I use Access to help them solve relatively simple business problems. Sometimes these are multi-user applications.
I provide the foregoing context because I cannot change a user's regional date settings as a means to resolve my problem.
I have a report that is used in the US (M/D/YY) and Canada (D/M/YY). The criteria dates are set by the user in unbound text boxes on a criteria form. When the user provides the start and end dates, I use a filter to filter the report.
The format for the text box is "mmm dd yyyy" to avoid the regional settings. The user can type it in or use the date picker calendar provided in Access 2007. Either way, when he/she chooses Oct 01 2010, the report still filters using Jan 10 2010 with Canadian regional settings.
I tried using the following code to standardize the date values.
On the cmdOK_Click event of the criteria form, the dates are captured thusly:
I thought if I took exactly what was in the text box then let Access convert the string using CDate, it would get it right. Then on the Report_Open event, the filter is applied as follows...
Didn't work.
I also tried populating a string variable then taking parts of the date value returned by the user's machine using the Left, Right and Mid functions. Then I translated them using the Month, Day and Year functions for the different parts.
Clunky but I thought if I took what the user's machine returned from the text box there would not be any question what the date parts were when the date variable dteStart translated for the filter. That didn't work when one of the user settings displayed the month or day with only one character (1/10/2010 or 10/1/2010). I could use Select Case to evaluate the permutations of what an individual's workstation might return but that seemed silly. It also doesn't solve whether the text box value is 1/10 or 10/1.
What is the ultimate solution to ensure a user in Canada and a user in the US get the same results when they run the report? Is the DateSerial function the right way to go? If so, how would I use it?
I provide the foregoing context because I cannot change a user's regional date settings as a means to resolve my problem.
I have a report that is used in the US (M/D/YY) and Canada (D/M/YY). The criteria dates are set by the user in unbound text boxes on a criteria form. When the user provides the start and end dates, I use a filter to filter the report.
The format for the text box is "mmm dd yyyy" to avoid the regional settings. The user can type it in or use the date picker calendar provided in Access 2007. Either way, when he/she chooses Oct 01 2010, the report still filters using Jan 10 2010 with Canadian regional settings.
I tried using the following code to standardize the date values.
On the cmdOK_Click event of the criteria form, the dates are captured thusly:
Code:
strStart = Format(txtStartDate, "mmm dd yyyy")
dteStart = CDate(strStart)
strEnd = Format(txtEndDate, "mmm dd yyyy")
dteEnd = CDate(strEnd)
I thought if I took exactly what was in the text box then let Access convert the string using CDate, it would get it right. Then on the Report_Open event, the filter is applied as follows...
Code:
Me.Filter = "ShiftDate Between #" & dteStart & "# and #" & dteEnd & "#"
Me.FilterOn = True
Didn't work.
I also tried populating a string variable then taking parts of the date value returned by the user's machine using the Left, Right and Mid functions. Then I translated them using the Month, Day and Year functions for the different parts.
Code:
strStartDate = Left(txtStartDate, 2) & "/" & Mid(txtStartDate, 3,2) & "/" & Right(txtStartDate,4)
dteStart = Month(strStartDate) & "/" & Day(strStartDate) & "/" & Year(strStartDate)
Clunky but I thought if I took what the user's machine returned from the text box there would not be any question what the date parts were when the date variable dteStart translated for the filter. That didn't work when one of the user settings displayed the month or day with only one character (1/10/2010 or 10/1/2010). I could use Select Case to evaluate the permutations of what an individual's workstation might return but that seemed silly. It also doesn't solve whether the text box value is 1/10 or 10/1.
What is the ultimate solution to ensure a user in Canada and a user in the US get the same results when they run the report? Is the DateSerial function the right way to go? If so, how would I use it?