Compile Error with Form Code (1 Viewer)

waxdart23

Registered User.
Local time
Today, 05:37
Joined
Nov 20, 2002
Messages
25
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 -
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
(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


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 have attached a jpg of the form to give an idea of what I was after.
 

Attachments

  • sickdb.jpg
    sickdb.jpg
    17.2 KB · Views: 120

waxdart23

Registered User.
Local time
Today, 05:37
Joined
Nov 20, 2002
Messages
25
additional info to above

The error I get highlights the following -
Recset As DAO.Recordset
 

Rich@ITTC

Registered User.
Local time
Today, 05:37
Joined
Jul 13, 2000
Messages
237
Which flavour/version of Access are you using?

If you are using 2000 or XP/2002 have you checked that you have the corrected references selected? You'll need:
Microsoft DAO 3.6 Object Library
in your list of References.

HTH

Rich
 

Users who are viewing this thread

Top Bottom