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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

intercept lostfocus 1

Status
Not open for further replies.

jpl458

Technical User
Sep 30, 2009
337
US
I have a data entry form where the first text box has the following code:

If gbl_Switch = 1 Then
Exit Sub
Else
End If

If Trim(Me.ID_Number & " ") = "" Then
MsgBox "Click OK, then enter an ID Number"
ID_Number.SetFocus
Exit Sub
Else
End If
Other code follows.

This bit makes sure that the user enters something into the box, which is what we want.

However, there are buttons on this form that open other forms, but the user is now trapped in the text box.

I have tried creating code in one of those buttons that sets a switch(Invisible textbox) to 1 on click, but the button does not set the switch on click, and does not open the other form, but the user is still trapped.

I get around this by removing the first bit of code from the inital textbox, and just check for blank entry then setfocus to the next textbox. Then I can use the buttons. But this is not spiffing. So the question is, can I trap the onlostfocus event, or is ther another way of doing this.

Any help or suggestions would be welcome.

jpl




 
How are ya jpl458 . . .

Put your code in the forms [blue]Before Update[blue] event:
Code:
[blue]   If Trim(Me.ID_Number & " ") = "" Then
      MsgBox "Click OK, then enter an ID Number"
      ID_Number.SetFocus
      [purple][b]Cancel = True[/b][/purple]
   End If[/blue]
This way the check is made only when you attempt to save the record. The user is free to navigate until then ...

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Very cool because it's simple.

Thanks so much

jpl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top