I have the following code, and basically it doesn't seem to return the correct value but instead is just jumping to the end of the function.
Public Function WorkingDays2(pstartdte As Date, penddte As Date) As Integer
On Error GoTo Err_WorkingDays2
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays", dbOpenSnapshot)
'start loop
Do While pstartdte <= penddte
For i = 1 To rst.RecordCount Step 1
MsgBox rst("HolidayDate")
rst.MoveNext
'if holiday date = date looping add to intcount
If HolidayDate = pstartdte Then
intCount = intCount + 1
End If
Next i
'Add to the count
pstartdte = pstartdte + 1
Loop
'It doesn't do this bit!
MsgBox (intCount)
WorkingDays2 = intCount
Exit_WorkingDays2:
Exit Function
Err_WorkingDays2:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays2
End Select
End Function
It's probably something simple, but I'm still learning VB so I can't quite understand this.
Public Function WorkingDays2(pstartdte As Date, penddte As Date) As Integer
On Error GoTo Err_WorkingDays2
Dim rst As DAO.Recordset
Dim DB As DAO.Database
Set DB = CurrentDb
Set rst = DB.OpenRecordset("SELECT [HolidayDate] FROM tblHolidays", dbOpenSnapshot)
'start loop
Do While pstartdte <= penddte
For i = 1 To rst.RecordCount Step 1
MsgBox rst("HolidayDate")
rst.MoveNext
'if holiday date = date looping add to intcount
If HolidayDate = pstartdte Then
intCount = intCount + 1
End If
Next i
'Add to the count
pstartdte = pstartdte + 1
Loop
'It doesn't do this bit!
MsgBox (intCount)
WorkingDays2 = intCount
Exit_WorkingDays2:
Exit Function
Err_WorkingDays2:
Select Case Err
Case Else
MsgBox Err.Description
Resume Exit_WorkingDays2
End Select
End Function
It's probably something simple, but I'm still learning VB so I can't quite understand this.