Problem with vb in form (1 Viewer)

JamesTierney

New member
Local time
Today, 15:04
Joined
Nov 4, 2015
Messages
2
I don't know if any one can help.
I have a form to add an appointment to a database and when I add an appointment and the appointment slot is already take I get a message saying its double booked. Thats ok.
But if I edit one of the appointments using the form and pick an appointment that is already booked I get an error message
run time error 2101
You cant go th the specific record.
here is my code.

Private Sub cboGoToRecord_AfterUpdate()
On Error Resume Next
Dim rst As Object
Set rst = Me.RecordsetClone
rst.FindFirst "AppointmentId = " & Me.cboGoToRecord.Value
Me.Bookmark = rst.Bookmark
End Sub

Private Sub cmdBack_Click()
On Error Resume Next
DoCmd.GoToRecord , , acPrevious
End Sub

Private Sub cmdFirst_Click()
On Error Resume Next
DoCmd.GoToRecord , , acFirst
End Sub

Private Sub cmdLast_Click()
On Error Resume Next
DoCmd.GoToRecord , , acLast
End Sub

Private Sub cmdNew_Click()
On Error Resume Next
DoCmd.GoToRecord , , acNewRec
End Sub

Private Sub cmdNext_Click()
On Error Resume Next
DoCmd.GoToRecord , , acNext
End Sub

Private Sub Delrec_Click()
Dim Response
Response = MsgBox("Are you sure you want to delete this Booked Appointment?", vbYesNoCancel + vbCritical, "KlassicKutts")
If Response = vbYes Then
CurrentDb.Execute ("DELETE * FROM tblAppointments WHERE AppointmentId=" & Me.AppointmentId)
Me.Requery
End If
End Sub

Private Sub Form_Current()
On Error Resume Next
If Me.CurrentRecord = 1 Then
Me.cmdBack.Enabled = False
Me.cmdFirst.Enabled = False
Else
Me.cmdBack.Enabled = True
Me.cmdFirst.Enabled = True
End If
If Me.CurrentRecord = Me.Recordset.RecordCount Then
Me.cmdLast.Enabled = False
Else
Me.cmdLast.Enabled = True
End If
If Me.CurrentRecord >= Me.Recordset.RecordCount Then
Me.cmdNext.Enabled = False
Else
Me.cmdNext.Enabled = True
End If
If Me.NewRecord Then
Me.cmdNew.Enabled = False
Else
Me.cmdNew.Enabled = True
End If
If Me.NewRecord Then
Me.lblRecordCounter.Caption = _
"Record " & Me.CurrentRecord & " of " & Me.Recordset.RecordCount + 1
Else
Me.lblRecordCounter.Caption = _
"Record " & Me.CurrentRecord & " of " & Me.Recordset.RecordCount
End If
Me.cboGoToRecord.Value = Me.AppointmentId.Value
End Sub

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3022 Then
MsgBox ("you have made a double booking. Please change appointment time or pick another Stylist who is available at that time.")
Response = 0
End If
End Sub

Private Sub Form_Load()

DoCmd.GoToRecord , , acLast

DoCmd.GoToRecord , , acFirst

End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:04
Joined
May 7, 2009
Messages
19,169
try debugging your code by putting a breakpoint at:

rivate Sub cboGoToRecord_AfterUpdate()
 

Users who are viewing this thread

Top Bottom