Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have to enforce an enterprise con

Status
Not open for further replies.
Jan 15, 2003
6
US
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? 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
 
After I added the DAO object in the references and re-ran the module I am now getting a "Data Type Mismatch in criteria expression" and it stops at the line: Set MySet = MyDB.OpenRecordset(MyQuery)

Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top