G
Guest
I am trying to load a dynamic array upon the opening of a form to create an
array of Holiday dates that I use in several places on the form to calculate
a date in the future using a function that strips weekend days and holidays.
The function calls for an array of dates where you put in array(#3/15/06#,
#3/20/06#) for example and it will skip the dates in question. This method
works but it requires someone (me) to update holidays every year or so in
code, not a desirable solution. I want to create an array on opening the
form that will create an array from a table so that the user can update the
holidays in the table every so often and not have to try and mess with the
code (or bug me to do it). I tried the following and I get only the first
date in the Holiday table when I try it so I am obviously missing somthing.
Any suggestions?
Public Sub Form_Load()
Dim HolKeys() As Date
Dim r As Integer
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenStatic
rst.Open "Select HolidayDate from Holidays"
r = 0
With rst
ReDim HolKeys(.RecordCount - 1)
Do Until .EOF
HolKeys(r) = ![Holidaydate]
.MoveNext
r = r + 1
Loop
.Close
End With
Debug.Print HolKeys(Holidaydate)
Set rst = Nothing
End Sub
array of Holiday dates that I use in several places on the form to calculate
a date in the future using a function that strips weekend days and holidays.
The function calls for an array of dates where you put in array(#3/15/06#,
#3/20/06#) for example and it will skip the dates in question. This method
works but it requires someone (me) to update holidays every year or so in
code, not a desirable solution. I want to create an array on opening the
form that will create an array from a table so that the user can update the
holidays in the table every so often and not have to try and mess with the
code (or bug me to do it). I tried the following and I get only the first
date in the Holiday table when I try it so I am obviously missing somthing.
Any suggestions?
Public Sub Form_Load()
Dim HolKeys() As Date
Dim r As Integer
Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenStatic
rst.Open "Select HolidayDate from Holidays"
r = 0
With rst
ReDim HolKeys(.RecordCount - 1)
Do Until .EOF
HolKeys(r) = ![Holidaydate]
.MoveNext
r = r + 1
Loop
.Close
End With
Debug.Print HolKeys(Holidaydate)
Set rst = Nothing
End Sub