Have "ENTER" run certain code instead of "next field"

B

BlueWolverine

Hello,
I am running Access 03 on XP Pro.

I have a form with three fields, SerNo, TagNum, and VINum. They are three
different ways of searching for a vehicle in my database.

So a user fills in one of them, and clicks the button below to search for
that vehicle.

The problem is, my user keeps typing in say 9XX12345 and hitting enter
hoping to activate the button, but that moves it to the next field. and i
have each field set up to blank the other fields "ON ENTER" (as in on
entering the field, not the enter key). This helps the button do its job
cleanly.

SerNo is always 8 long, TagNo is always 7 long, and VINum is always 17 long
is there any way to make it such that hitting the ENTER key after filling in
the field causes the search button to run its code?

Thank you!
 
K

Klatuu

Use the After Update event of each control to cause the button code to run.
You can also use the Before Update event to check to make sure it is the
correct length:

Private Sub txtSerNo_BeforeUpdate()

If Len(Me.txtSerNo) <> 8 Then
MsgBox "Serial Number Must be Eight Characters"
Cancel = True
End If

End Sub

Private Sub txtSerNo_AfterUpdate()
Call cmdSearch_Click
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top