How to evaluate entry and show MsgBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a field ([Type]) that I only want to accept the letters O, W and D.
If the user doesn't enter one of these letters, I want a message box to pop
up saying "You must enter an 'O', 'W' or 'D'" with an OK button.

THEN, when they hit the OK button, I want the focus to return to the Type
field, ready to accept a correct entry. SetFocus hasn't worked, or I'm not
coding it correctly.

So, I need help in 1) evaluating the entry and 2) returning focus to the
Type field.

Thanks.

Jerry
 
If Me.Type <> "O" And Me.Type <> "W" And Me.Type <> "D" Then
Msgbox "You must enter an 'O', 'W' or 'D'", vbOkOnly
Me.Type.SetFocus
End If
 
You can use a combo that will list this letters, value list O;W;D, and set
the limit to list properties of the combo to Yes.
That way the user wont be able to select any other letters
 
Doug, the first part works, but the SetFocus isn't working properly. It
advances to the next field when you click the OK on the MsgBox. Could it be
because I have the code in AfterUpdate?

Jerry

Douglas J Steele said:
If Me.Type <> "O" And Me.Type <> "W" And Me.Type <> "D" Then
Msgbox "You must enter an 'O', 'W' or 'D'", vbOkOnly
Me.Type.SetFocus
End If

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


JWCrosby said:
I have a field ([Type]) that I only want to accept the letters O, W and D.
If the user doesn't enter one of these letters, I want a message box to pop
up saying "You must enter an 'O', 'W' or 'D'" with an OK button.

THEN, when they hit the OK button, I want the focus to return to the Type
field, ready to accept a correct entry. SetFocus hasn't worked, or I'm not
coding it correctly.

So, I need help in 1) evaluating the entry and 2) returning focus to the
Type field.

Thanks.

Jerry
 
Jeez....

Just do it in the Properties for the control. Fill in the desired values in
the Validation Ruleproperty, and the text of the Msgbox in the Validation
Text property.

End of issue....
 
Use the Before update event of the field and use the code

If Me.Type <> "O" And Me.Type <> "W" And Me.Type <> "D" Then
Msgbox "You must enter an 'O', 'W' or 'D'", vbOkOnly
Cancel = True ' wont let the user exit the field
End If


--
Good Luck
BS"D


JWCrosby said:
Doug, the first part works, but the SetFocus isn't working properly. It
advances to the next field when you click the OK on the MsgBox. Could it be
because I have the code in AfterUpdate?

Jerry

Douglas J Steele said:
If Me.Type <> "O" And Me.Type <> "W" And Me.Type <> "D" Then
Msgbox "You must enter an 'O', 'W' or 'D'", vbOkOnly
Me.Type.SetFocus
End If

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


JWCrosby said:
I have a field ([Type]) that I only want to accept the letters O, W and D.
If the user doesn't enter one of these letters, I want a message box to pop
up saying "You must enter an 'O', 'W' or 'D'" with an OK button.

THEN, when they hit the OK button, I want the focus to return to the Type
field, ready to accept a correct entry. SetFocus hasn't worked, or I'm not
coding it correctly.

So, I need help in 1) evaluating the entry and 2) returning focus to the
Type field.

Thanks.

Jerry
 
Back
Top