form: cursor stays on field until user enters data

M

Mark

Hi,

I am still having difficultly in getting the following to
work. Any assistance would be greatly appreciated.

I have a form that I will get a user to fill out with a
couple of mandatory fields/text boxes I'd like them to
fill in. And when they don't fill in the mandatory
field... a message pops up saying that they need to fill
in the field. In addition and my problem, I would like
the cursor to stay on that field before moving onto the
next field/text box.

In the text box properties, I have an [Event Procedure]
for both "AfterUpdate" and "OnExit" which pops up a
message to the user entering data into the form to enter
the information. Which works fine... however, I would
like to have the cursor stay on that particular field/text
box before continuing to the next field. I've tried
placing the code listed below in the "AfterUpdate"
and "OnExit" thinking that this would work, but it moves
the cursor to the next text box once the message
window/prompt is clicked "ok". I even placed ":
TextBoxName.SetFocus" in the If... Then statement thinking
this would work... I've listed the code below. Also, I
have tried turning the "required field properties" to yes
and no. What am I not doing right? Would the "validation
rule" and "validation text" properties be used to do
this. I am sure there is more than one way to get this to
work. I can't seem to figure this out. Can you help
me?

Thanks, Mark

Below is the code I have been working with in
the "AfterUpdate" section:

Private Sub Referral_Date_AfterUpdate()
If (IsNull(Me.Referral_Date) Or Me.Referral_Date = "")
Then
MsgBox "This is a mandatory field, please enter a response
here before proceeding. If not, you will be asked again to
enter this data before exiting this page.":
Referral_Date.SetFocus
End If
End Sub
 
R

Rick Brandt

Mark said:
Hi,

I am still having difficultly in getting the following to
work. Any assistance would be greatly appreciated.

I have a form that I will get a user to fill out with a
couple of mandatory fields/text boxes I'd like them to
fill in. And when they don't fill in the mandatory
field... a message pops up saying that they need to fill
in the field. In addition and my problem, I would like
the cursor to stay on that field before moving onto the
next field/text box.

In the text box properties, I have an [Event Procedure]
for both "AfterUpdate" and "OnExit"

Use BeforeUpdate and set Cancel = True. Then the update never occurs and the cursor
stays in the control. I would actually use the BeforeUpdate of the form myself.
What if the user never gives the required control focus at all?
 
T

TC

You need to do your check in the BeforeUpdate event. (AfterUpdate and Exit
are both too late.) BeforeUpdate has a Cancel argument. If you set Cancel to
True, the cursor will stay in the field.

HTH,
TC
 

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