CoreyWayne
MIS
I have to enforce an enterprise constraint where an instructor can not have two appointments at the same time. The code that I got out of a newer Database Management book does not like the - Dim MyDB as Database - line of code. The code for the before update on the form is below. Anyone have any thoughts on why this error on the dim line is? Or any better suggestion to enforce this contraint? Thank you in advance.
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim MyDB As Database
Dim MySet As Recordset
Dim MyQuery As String
'Set up query to select all matching records
MyQuery = "SELECT StaffID, Date, Time FROM Appointments WHERE StaffID='StaffID'AND Date='Date' AND Time='Time'"
'Open Database and run query'
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MySet = MyDB.OpenRecordset(MyQuery)
If (MySet.RecordCount > 1) Then
MsgBox "Time and date unavailable. Please Re-schedule"
Me.Undo
End If
MySet.Close
MyDB.Close
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim MyDB As Database
Dim MySet As Recordset
Dim MyQuery As String
'Set up query to select all matching records
MyQuery = "SELECT StaffID, Date, Time FROM Appointments WHERE StaffID='StaffID'AND Date='Date' AND Time='Time'"
'Open Database and run query'
Set MyDB = DBEngine.Workspaces(0).Databases(0)
Set MySet = MyDB.OpenRecordset(MyQuery)
If (MySet.RecordCount > 1) Then
MsgBox "Time and date unavailable. Please Re-schedule"
Me.Undo
End If
MySet.Close
MyDB.Close
End Sub