Switching to a record by pressing a key

Danielf

Registered User.
Local time
Today, 19:32
Joined
Feb 21, 2000
Messages
103
I have a continuous form with a field based
on customers names sorted in descending order.
I would like when pressing a letter key that
the cursor goes to the first record with
this letter as first letter. For example when
pressing "T" , the cursor has to go to the first customers name beginning with a "T"

I don't know how to do this.

Thanks for help

Daniel
 
On your form Under the Events tab.

Change the following line

KeyPreview = False to True

Then add this code to the Forms OnKeyPress Event.

Private Sub Form_KeyPress(KeyAscii As Integer)
dim rst as Recordset '(Access 2000 DAO.Recordset)

'You will need to convert the KeyAscii to a Letter

if (KeyAscii >= 65 and KeyAscii<= 90) or (KeyAscii >= 97 and KeyAscii<= 122)
then
set rst=me.recordsetclone
rst.Findfirst "left[Name]=" & chr(KeyAscii)
if not rst.NoMatch then me.Bookmark = rst.Bookmark
set rst = nothing
KeyAscii = 0
end if
End Sub

This sub will move you two the first [Name] field that starts with your letter value. By doing it this way you will not be able to type. You may want to add a toggle button for editing. then just add an if statement before the evaluation of the letter.
 
Thank you very much
 
BUT :
I have written the code but when I am pressing a key I am receiving the following
eerror message :Runtime error 3070,
the microsoft jet database engine does not recognize "(the pressed letter)" as a valid
field name or expression.

I have received many times this error message with the FindFirst method.
Does it come because I have splitted my program and data in two databases?

Daniel
 
No, It comes because I type the code to fast. Here is the correction:

Change:
rst.Findfirst "left[Name]=" & chr(KeyAscii)

To:
rst.Findfirst "left([Name])=" & chr(KeyAscii)

'Make sure [Name] is the name of your field, otherwise just replace 'Name' with the name of the field you are working with.

I appoligize for the code error.
 
Hi Travis,

I have tried already before the change that you wrote but then I am receiving the error
message:

Runtime eror 3077, wrong number
of arguments used with function in expression.
I have tried :

rst.Findfirst "left$([Name],1)=" & chr(KeyAscii) but then I am receiving the first
error message
 

Users who are viewing this thread

Back
Top Bottom