Return user into field

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
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.
 
Back
Top