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

Lost Focus Event Problem 2

Status
Not open for further replies.

altoona

Programmer
Jul 31, 2001
7
US
I have two fields on a form. The first field has a default value of 0. If someone hits enter and accepts this ( a value I don't want them to enter) I have the lost focus event check the value and return the focus back into the first field till they get it right. The trouble is .. the focus always ends up in the second field.

Here my code.

Private Sub fieldone_lostfocus()

If Me.fieldone = 0 then
Me.fieldone.setfocus
end if

Help!!!!

 
Why not add a validation rule to this control and set it to >0 and a Validation Text of "Enter a value greater than 0". Then access does all the work for you...

Joe Miller
joe.miller@flotech.net
 
You're close.

Change the event to on exit.

Private Sub fieldone_OnExit(Cancel as boolean)

If Me.fieldone = 0 then
msgbox "Please enter something othe than 0" 'Optional
cancel = true
Else
Cancel = False
End Sub



 
Another solution I have used before is to move the code to the got focus event of the second field.

HTH
 
Interesting information about the Got Focus event.

You cannot assign the focus to a control that already has the focus. If you wish to assign the focus to a control you have just left (or tried to leave) you'll need to set the focus to some other control and then back to the one you really want to have it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top