I'm trying to use code to set validation which checks if the value of Audience is "other" then the value of the control Other cannot be empty. It works fine while I'm in the subform. However, if I click out of the subform it puts focus where the user clicked.
I tried putting the code on the BeforeUpdate event of the subform and the control to make sure that the user couldn't bypass the validation. However, if I click out of the subform, the code triggers the message box but then when user says OK (which should set focus back to the empty field) it puts focus where the user clicked.
(Rural Guy: This is the same database -- Centralized Data Collection -- that you've been helping me on)
My code for the control is as follows:
________________________________________________________________________________________
Private Sub Other_Exit(Cancel As Integer)
If Me.cboAudience = "Other" And (IsNull(Me.Other) Or Me.Other = "") Then
If MsgBox("If you entered Other as your audience, you must enter what the Other is in order to continue. Choose OK to enter Other. Choose Cancel to clear Audience choice and try again.", vbOKCancel, "Other is required!") = vbOK Then
Me.Parent.sfrmAudience.SetFocus
Forms!frmEvents.sfrmAudience.Form!Other.SetFocus
Else
Me.cboAudience.Value = Null
Me!cboAudience.SetFocus
End If
Exit Sub
End If
I tried putting the code on the BeforeUpdate event of the subform and the control to make sure that the user couldn't bypass the validation. However, if I click out of the subform, the code triggers the message box but then when user says OK (which should set focus back to the empty field) it puts focus where the user clicked.
(Rural Guy: This is the same database -- Centralized Data Collection -- that you've been helping me on)
My code for the control is as follows:
________________________________________________________________________________________
Private Sub Other_Exit(Cancel As Integer)
If Me.cboAudience = "Other" And (IsNull(Me.Other) Or Me.Other = "") Then
If MsgBox("If you entered Other as your audience, you must enter what the Other is in order to continue. Choose OK to enter Other. Choose Cancel to clear Audience choice and try again.", vbOKCancel, "Other is required!") = vbOK Then
Me.Parent.sfrmAudience.SetFocus
Forms!frmEvents.sfrmAudience.Form!Other.SetFocus
Else
Me.cboAudience.Value = Null
Me!cboAudience.SetFocus
End If
Exit Sub
End If