Hi All,
I'm trying to create a function that returns true if a supplied date is during a State holiday e.g. during Easter.
I've got a table called StateHolidays.
It lists each holiday with a From & To date.
After trawling through Access's help and leaching some example code I came up with this:
Function IsStateHoliday(InputDate As Date) As Boolean
Dim dbs database
Dim rst As Recordset
dbs = CurrentDb
Set rst = dbs.OpenRecordset("StateHolidays")
rst.Index = "StateHolidayID"
rst.MoveFirst
rst.Filter = "StateHolidayFrom >= #" & InputDate & "# and StateHolidayTo <= #" & InputDate & "#"
IsStateHoliday = rst.EOF
rst.Close
End Function
Unfortunately when I execute it access doesn't recognise the type 'Database' although the help tells me that CurrentDb returns this type.
Anyway - whatever - I can't get this to work. Could someone suggest either a better way of doing this or point out what is wrong with my code.
Thanks in advance for any and all help
TTFN
Marc
I'm trying to create a function that returns true if a supplied date is during a State holiday e.g. during Easter.
I've got a table called StateHolidays.
It lists each holiday with a From & To date.
After trawling through Access's help and leaching some example code I came up with this:
Function IsStateHoliday(InputDate As Date) As Boolean
Dim dbs database
Dim rst As Recordset
dbs = CurrentDb
Set rst = dbs.OpenRecordset("StateHolidays")
rst.Index = "StateHolidayID"
rst.MoveFirst
rst.Filter = "StateHolidayFrom >= #" & InputDate & "# and StateHolidayTo <= #" & InputDate & "#"
IsStateHoliday = rst.EOF
rst.Close
End Function
Unfortunately when I execute it access doesn't recognise the type 'Database' although the help tells me that CurrentDb returns this type.
Anyway - whatever - I can't get this to work. Could someone suggest either a better way of doing this or point out what is wrong with my code.
Thanks in advance for any and all help
TTFN
Marc