This code works fine, the Windows regional settings are UK
(dd/mm/yyyy) but when it reads the record set it recognises them as US
dates - mm/dd/yyyy. All dates are formatted as short dates. Would like
to know how to overcome this and why it does it.
Public Function HowDays(StartDate As Date, EndDate As Date) As Integer
'Get the number of workdays between the given dates
Dim dbs As DAO.Database
Dim rstHolidays As DAO.Recordset
Dim Idx As Long
Dim MyDate As Date
Dim NumDays As Long
Dim strCriteria As String
Dim NumSgn As String * 1
Set dbs = CurrentDb
Set rstHolidays = dbs.OpenRecordset("tblHolidays", dbOpenDynaset)
NumSgn = Chr(35)
MyDate = FormatDateTime(StartDate, vbShortDate)
For Idx = CLng(StartDate) To CLng(EndDate)
Select Case (Weekday(MyDate))
Case Is = 1 'Sunday
'Do Nothing, it is NOT a Workday
Case Is = 7 'Saturday
'Do Nothing, it is NOT a Workday
Case Else 'Normal Workday
strCriteria = "[HoliDate] =" & NumSgn & MyDate &
NumSgn
rstHolidays.FindFirst strCriteria
If (rstHolidays.NoMatch) Then
NumDays = NumDays + 1
Else
'Do Nothing, it is NOT a Workday
End If
End Select
MyDate = DateAdd("d", 1, MyDate)
Next Idx
HowDays = NumDays
End Function