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!

"Freeze" a textbox until entry is correct

Status
Not open for further replies.

pdtit

Technical User
Nov 4, 2001
206
BE
I have an unbound textbox on my form, used to enter an amount of money a customer paid cash.

I want to check the entry in this box; if the field is blank or 0, it would show a msgbox that the entry is incorrect.

I used something like the code below :

Private Sub Cash_LostFocus()
If Cash.Value < 1 Then
If MsgBox(&quot;msg here ??&quot;, vbYesNo + vbQuestion , &quot;title here&quot;) = vbNo Then
cash.setfocus
End If

End Sub

When the value is less than 1, it indeed gives the messagebox, but it always jumps to the next control.
I also tried docmd.gotocontrol cash

but that also doesn't work.

Anyone ?

Peter
 
Hi Peter!

Put the code in the BeforeUpdate Event procedure for the textbox. Then instead of setting the focus just put Cancel = -1 and it will automatically keep the focus in the text box.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top