Danielf
05-27-2000, 07:22 AM
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
Travis
05-27-2000, 02:27 PM
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.
Danielf
05-28-2000, 02:06 AM
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
Travis
05-28-2000, 09:14 PM
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.
Danielf
05-28-2000, 10:42 PM
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