AbacusInfoTech
asked on
Placing of code to supress error messages (DoCmd.SetWarnings)
Hello experts.
I have the following code in a popup form that stops the form opening if there are no records to display:
Private Sub form_open(Cancel As Integer)
DoCmd.SetWarnings (False)
If Me.RecordsetClone.RecordCo unt = 0 Then
MsgBox "There are no records to display within your search criteria."
Cancel = True
End If
DoCmd.SetWarnings (True)
End Sub
This works fine, but once I 'OK' my own message box as coded above, I get the defaut access error message 'The openform action was cancelled'. It is this error message I want to supress so I must be placing my "DoCmd.SetWarnings" in the wrong place...
Rem'ing out the DoCmd.SetWarnings (True) doesn't even help, so am I even using the right code?
I have the following code in a popup form that stops the form opening if there are no records to display:
Private Sub form_open(Cancel As Integer)
DoCmd.SetWarnings (False)
If Me.RecordsetClone.RecordCo
MsgBox "There are no records to display within your search criteria."
Cancel = True
End If
DoCmd.SetWarnings (True)
End Sub
This works fine, but once I 'OK' my own message box as coded above, I get the defaut access error message 'The openform action was cancelled'. It is this error message I want to supress so I must be placing my "DoCmd.SetWarnings" in the wrong place...
Rem'ing out the DoCmd.SetWarnings (True) doesn't even help, so am I even using the right code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Fine.
Thanks
Pete
Thanks
Pete
ASKER
FYI My main form's code is:
Private Sub BtnConsultantPicker_Click(
On Error GoTo Err_BtnConsultantPicker_Cl
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "FrmUserPopJobs"
stLinkCriteria = "[consultantid]=" & Me![CboConsultantPicker]
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_BtnConsultantPicker_C
Exit Sub
Err_BtnConsultantPicker_Cl
If Err.Number = 2501 Then
Resume Exit_BtnConsultantPicker_C
End If
MsgBox Err.description
Resume Exit_BtnConsultantPicker_C
End Sub
And my Form code is now:
Private Sub form_open(Cancel As Integer)
If Me.RecordsetClone.RecordCo
MsgBox "There are no records to display within your search criteria."
Cancel = True
End If
End Sub