I hope the code below is clear - I trimmed out construction of comments (string strM).
This has a linked Jet/ACE back end accdb. The first part of the main If/End if works perfectly, not allowing the user to have three check boxes turned off.
The second part looks to see if there is an active filter, with filterOn off or on. It works if I click OK. However there is odd behaviour when I click vbCancel on the msgbox.
After clicking cancel on the msgbox, the check box remains checked or unchecked - whatever it was, before. It appears to have worked. However, when I go to click or right click anywhere else on my form or subform, the msgbox appears again and continues to do so if I click cancel.
When I OK on second or subsequent appearances of the msgbox stops the darn thing from reappearing. It also does not change the check box. Remember that the check box WILL change if I press OK on the first go.
Have I messed this up by having a if msgbox ("choices", vbokcancel) in the before_update event? Or have I done something even more obviously stupid?
Thanks in advance for any suggestions.
Code:
Private Sub chkShowBldg_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Proc
Dim strM As String
If Me.chkShowBldg = 0 And Me.chkShowEqpt = 0 And Me.chkShowSpace = 0 Then
MsgBox "At least one of Show Equipment, Show Building Components, or Show Space " & _
"must be checked.", vbInformation, "All Three Check Boxes Cannot Be Turned Off"
Cancel = True
ElseIf Forms!frmMain.subData.Form.Filter <> "" Then
If Forms!frmMain.subData.Form.FilterOn = True Then
strM = "You have active filters that are turned on in the main screen (see the ""Filtered"" "
'More msg stuff snipped
Else
strM = "You have filters active on the main screen, but they are turned off (see the ""Unfiltered"" "
'More msg stuff snipped
End If
'Other msg stuff snipped
If MsgBox(strM, vbInformation + vbOKCancel + vbDefaultButton2, _
"Please Take Note! Click OK to Continue") = vbCancel Then
Cancel = True
End If
End If
Exit_Proc:
Exit Sub
Err_Proc:
Select Case Err.Number
Case Else
MsgBox "Error " & Err.Number & " " & Err.Description, vbCritical, "Error frmMain chkShowBldg_BeforeUpdate" _
, Err.HelpFile, Err.HelpContext
Resume Exit_Proc
End Select
End Sub