Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Persistent focus 2

Status
Not open for further replies.

lachesis

Technical User
Sep 25, 2002
138
NZ
Hi,

Im setting up a Registration form. Two of the fields are CompanyName and UserName. I want both of these fields to have data in them of a certain type and format before the user can move on to complete other fields.

I've set up validations in the AfterUpdate and LostFocus events for these unbound fields. The problem is that I cannot get the VBA code to persist in maintaining focus, even when (clearly) the data in them does not meet the validation criteria.

Here's my AfterUpdate event code:

' validate Company Name input
If (Len(Trim(Me!txtCoName.Value & &quot;&quot;)) < 3) Then
MsgBox &quot;Name is too short!&quot; & Chr(13) & _
&quot;Please use a longer name.&quot;
Me!txtCoName.SetFocus
Else
' do nothing
End If

I've also turned off tab stops on all the other fields on the form.

What am I missing here??
thanks L.
 
You need to change the Me! to Me.

The ! is used for the form.

Steve
 
Hi lachesis!

The control still has focus, and cannot setfocus to itself. One workaround is to setfocus to another control, then back.

[tt]If (Len(Trim(Me!txtCoName.Value & &quot;&quot;)) < 3) Then
MsgBox &quot;Name is too short!&quot; & Chr(13) & _
&quot;Please use a longer name.&quot;
Me!txtSomeOtherControl.SetFocus
Me!txtCoName.SetFocus
Else
' do nothing
End If[/tt]

Roy-Vidar
 
Sorry Steve, that's not doing it either.

L.
 
lachesis,

Apologies, I believe there is a way to cancel the next event so you do not have to move to another control then back.

I will look into it and make sure that what I think will work actually will.


Steve
 
Thanks roy. Looks like my original thank-you post didnt fire for some reason.

cheers L.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top