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

Read input from keyboard and perform appropriate functions

Status
Not open for further replies.

xinyin

Programmer
Jan 16, 2003
81
HK
I have a continuous form (set to "no edit") displaying a list of people's names, in ascending order. I want a VBA code so that when I press a key, for example "J", the curser will go to the first record which its name starts with letter "J", for example "John". However, this is NOT a filter, since I just want the curser to go to position of "J" only, after that you can press up arrow to reach upper/previous records, or press another letter key to go for other names. This is the code I am writing, it is not working, why?

Private Sub Form_KeyPress(KeyAscii As Integer)
Dim TargetCode As String

DoCmd.GoToRecord , , acFirst

Do Until KeyAscii = TargetCode
TargetCode = Left(Name.Value, 1)
DoCmd.GoToRecord , , acNext
Loop
End Sub

I also want to know if I can add a "non-letter proof" feature, that is, to ignore any symbol input such as +,?,!,(,*..., but I want numbers to be allowed. Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top