paulwoods23
IS-IT--Management
I have a form which, after selecting a "Staff" record and a year from two seperate comb boxes should list all sickness records for the selections in a list box.
I am using the following code to do this -
(the bit at the start where I convert a year to a start and end date is not complete yet!)
When I run this I get the following error -
Compile Error:
User-defined type not defined
The error I get highlights the following -
Recset As DAO.Recordset
I have used this code in a similar form in a seperate database and it works fine. It's not my code and I'm not in contact with the person who wrote it, does anyone have any ideas why I get this error?
I am using the following code to do this -
Code:
Private Sub cmbYearSelect_AfterUpdate()
Dim StartDate As Date
Dim EndDate As Date
If cmbYearSelect = "2002" Then
StartDate = "01/01/2002" And EndDate = "31/12/2002"
End If
If IsNull(cmbYearSelect) And IsNull(cmbNameSearch) Then
lstSicknessCount.RowSource = ""
lstSicknessCount.Requery
Else
Dim strSQL As String
strSQL = "SELECT tblSickness.StartDate, tblSickness.ReturnDate, tblSicknessTypes.SicknessType, " _
& "tblSickness.TotalDays FROM (tblStaffDetails INNER JOIN tblSickness ON tblStaffDetails.StaffNumber " _
& "= tblSickness.StaffNumber) INNER JOIN tblSicknessTypes ON tblSickness.ID = tblSicknessTypes.ID " _
& "WHERE (((tblSickness.StartDate)>=" & StartDate & ") AND ((tblSickness.ReturnDate)<=" & EndDate & "));"
lstSicknessCount.RowSourceType = "Table/Query"
lstSicknessCount.RowSource = strSQL
lstSicknessCount.Requery
End If
Dim Recset As DAO.Recordset
Dim SicknessQdf As QueryDef
Dim Dbs As Database
Dim NoOfDays As Long
Set Dbs = CurrentDb()
Set SicknessQdf = Dbs.CreateQueryDef("", strSQL)
Set Recset = SicknessQdf.OpenRecordset
With Recset
If Not Recset.BOF And Not Recset.EOF Then
Recset.MoveFirst
Recset.MoveLast
NoOfDays = .RecordCount
Else
NoOfDays = 0
End If
Recset.Close
Set Recset = Nothing
Set SicknessQdf = Nothing
End With
Me.NoDays = NoOfDays
End Sub
When I run this I get the following error -
Compile Error:
User-defined type not defined
The error I get highlights the following -
Recset As DAO.Recordset
I have used this code in a similar form in a seperate database and it works fine. It's not my code and I'm not in contact with the person who wrote it, does anyone have any ideas why I get this error?