Return user into field

G

Guest

Hi all,

I want to check on exit the text field on my form (whether the user input
information with single spacing or double spacing) and to return him into the
field for editing if spacing is double.

I put the below code on After Update:

If Me.[ToFrom1] Like ("*" + " " + "*") Then
MsgBox "Please remove double spacing!"
Me.ToFrom1.SetFocus
Else
End If

The code works, except it wouldnt return the user into the same field.
So probably I need something else than "SetFocus" thing...

Can anybody help?

Thank you.
Lana
 
M

Marshall Barton

Lana said:
I want to check on exit the text field on my form (whether the user input
information with single spacing or double spacing) and to return him into the
field for editing if spacing is double.

I put the below code on After Update:

If Me.[ToFrom1] Like ("*" + " " + "*") Then
MsgBox "Please remove double spacing!"
Me.ToFrom1.SetFocus
Else
End If

The code works, except it wouldnt return the user into the same field.
So probably I need something else than "SetFocus" thing...


You can not change the focus in the AfterUpdate event
because the focus is already in the process of moving.

Regardless of that issue you should check this kind of thing
in the BeforeUpdate event where, instead of fooling around
with the focus, you can ancel the event by simply using the
line:
Cancel = True
 
W

Wayne Morgan

It may be easier just to remove the double spacing for the user.

In the control's AfterUpdate event, try:

Do While InStr(Me.ToFrom1, " ") > 0
Me.ToFrom1 = Replace(Me.ToFrom1, " ", " ")
Loop

To clarify the above,

Do While InStr(Me.ToFrom1, "DoubleSpace") > 0
Me.ToFrom1 = Replace(Me.ToFrom1, "DoubleSpace", "SingleSpace")
Loop

This will find all double, triple, or more spaces and reduce them to a
single space.
 

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