When form opens buttons dont work until I hit New then they work

jamesgtierney

Registered User.
Local time
Today, 16:40
Joined
Jan 28, 2016
Messages
24
Option Compare Database

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
 
if something's wrong, you wont know ,because you turned off the error messages with
On Error Resume Next
 
They were working alright until I added this

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
 
Access doesn't always load an entire RecordSet when a Form opens, and sometimes forcing it to so can solve this kind of problem. Try this:

Code:
Private Sub Form_Load()

 DoCmd.GoToRecord , , acLast
 
 DoCmd.GoToRecord , , acFirst

End Sub
It's also possible that the Delrec Command Button is corrupted. Although we usually think of Forms, or entire Databases, when we speak of corruption, individual Controls, such as Command Buttons, can and do become corrupted. The test and the fix are one and the same; deleting the Control then re-creating it! If it was corrupt, you've verified the fact and solved the problem! If not, you've only lost a minute or two!

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom