I have the following code to test if a recordset is empty and if so delete a record, if not a msgbox telling them it is not empty basically. It ALWAYS seems to find matches in the recordset, even if there aren't any even if I set MySQL to a constant instead of Me!lstSchedule. help.
Private Sub Label14_Click()
Dim MyDB As DAO.Database
Dim MyRecs As DAO.Recordset
Dim MySQL As String
MySQL = "SELECT * FROM tblEnrolled WHERE eScheduleID= " & Me!lstSchedule
Set MyDB = CurrentDb
Set MyRecs = MyDB.OpenRecordset(MySQL)
If MyRecs.NoMatch Then
'Deletes from Schedule if no one is enrolled
DoCmd.RunSQL "DELETE * from tblSchedule WHERE ScheduleID =" & Me.lstSchedule & ";"
Else
MsgBox "There are people enrolled in the course. Please have them Unregister and then delete the course", vbOKOnly
End If
'Refreshes list
lstSchedule.Requery
End Sub
Thanks in advance for any help.
Private Sub Label14_Click()
Dim MyDB As DAO.Database
Dim MyRecs As DAO.Recordset
Dim MySQL As String
MySQL = "SELECT * FROM tblEnrolled WHERE eScheduleID= " & Me!lstSchedule
Set MyDB = CurrentDb
Set MyRecs = MyDB.OpenRecordset(MySQL)
If MyRecs.NoMatch Then
'Deletes from Schedule if no one is enrolled
DoCmd.RunSQL "DELETE * from tblSchedule WHERE ScheduleID =" & Me.lstSchedule & ";"
Else
MsgBox "There are people enrolled in the course. Please have them Unregister and then delete the course", vbOKOnly
End If
'Refreshes list
lstSchedule.Requery
End Sub
Thanks in advance for any help.