Test for field content not working

G

Guest

Hi. I am using 2003.

I need to test if a field is null. If it is, I need a message box to open
and ask if the field is supposed to be blank. The user can choose Yes or No.
This part is working OK.

The problem is: If the field should not be left blank and the user chooses
No, then I need the focus to return to the field in question. My code is not
capturing the answer from the message box. I have tried many different
methods........

My code is as follows:

Private Sub AOANumbers_Exit(Cancel As Integer)
On Error GoTo AOANumbers_Err

Dim Msg, Style, Title, Response
Msg = "Should the AOA Number be Blank?"
Style = vbYesNo + vbDefaultButton2
Title = "AOA Numbers"

If IsNull(AOANumbers) Then
Beep
Response = MsgBox(Msg, Style, Title)
If Response = vbNo Then
Forms!frmDataEntryForm!AOANumbers.SetFocus
Else
Forms!frmDataEntryForm!strWGArea.SetFocus
End If
End If

AOANumbers_Exit:
Exit Sub

AOANumbers_Err:
MsgBox Error$
Resume AOANumbers_Exit
End Sub

If somebody could fix this for me, I would be extremely grateful.

TIA
 
G

Graeme Richardson

Hi, rather than set the focus back to the control, set the event's Cancel
argument to True.

If IsNull(AOANumbers) Then
Beep
Response = MsgBox(Msg, Style, Title)
If Response = vbNo Then
Cancel = True
Else
Forms!frmDataEntryForm!strWGArea.SetFocus
End If
End If

HTH, Graeme.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top