"msgbox" response problem

D

David##

I have a routine that validates data. If VALID, nothing
happens. If INVALID, I have a vbOKOnly msgbox stating the
error. After the msg displays, I want to set focus back to
the field with the bad data. Instead, focus goes to the
next field regardless of where I stick a "SetFocus"
command. How do I direct to the bad field without
depending on the user to go there?
 
R

Rick Brandt

David## said:
I have a routine that validates data. If VALID, nothing
happens. If INVALID, I have a vbOKOnly msgbox stating the
error. After the msg displays, I want to set focus back to
the field with the bad data. Instead, focus goes to the
next field regardless of where I stick a "SetFocus"
command. How do I direct to the bad field without
depending on the user to go there?

This code should be run in the BeforeUpdate event because it has a Cancel
argument which prevents the field from ever losing focus in the first place
thus eliminating the need to set the focus back.

If (SomeTest) = True Then
MsgBox "Try Again"
Cancel = True
Me.NameOfControl.Undo
End If
 
M

Marshall Barton

David## said:
I have a routine that validates data. If VALID, nothing
happens. If INVALID, I have a vbOKOnly msgbox stating the
error. After the msg displays, I want to set focus back to
the field with the bad data. Instead, focus goes to the
next field regardless of where I stick a "SetFocus"
command. How do I direct to the bad field without
depending on the user to go there?


Where do you have the routine?

If it's in an AfterUpdate event, move it to the BeforeUpdate
event and instead of using SetFocus use Cancel = True
 
G

Guest

Thanx -
I was sitting in the "Afterupdate" event
-----Original Message-----


This code should be run in the BeforeUpdate event because it has a Cancel
argument which prevents the field from ever losing focus in the first place
thus eliminating the need to set the focus back.

If (SomeTest) = True Then
MsgBox "Try Again"
Cancel = True
Me.NameOfControl.Undo
End If


--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


.
 
G

Guest

Thanx - I WAS at "afterupdate"
-----Original Message-----



Where do you have the routine?

If it's in an AfterUpdate event, move it to the BeforeUpdate
event and instead of using SetFocus use Cancel = True
 

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