moving in a tabular form

maxmangion

AWF VIP
Local time
Today, 10:33
Joined
Feb 26, 2003
Messages
2,805
i have a tabular form and i would like that when i press the up or down arrow key, i would move to the next/previous record rather than the next/previous field.

which of the following codes do you think it's best to use:

Code:
select case keycode
case vbkeydown
docmd.gotorecord , , acnext
keycode = 0
case vbkeyup
docmd.gotorecord , , acprevious
keycode = 0
case else
end select

or

Code:
 if keycode = 40 then
docmd.gotorecord , , acnext
keycode = 0
else
if keycode = 38 then
docmd.gotorecord , , acprevious
keycode = 0
end if
end if

thanks you!
 
select case, easier to read, easier to expand.
 
thx!

however, i am noticing a small problem with that code. if i am at the first record and i hit the up arrow key i am getting an error message. similarly with down arrow key when i am at the last record. what shall i do to prevent this error ?

thanks!
 
doing it in the following manner, is it correct ?

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDown
If Me.CurrentRecord <> acLast Then
DoCmd.GoToRecord , , acNext
KeyCode = 0
Else
DoCmd.GoToRecord , , acFirst
End If
Case vbKeyUp
If Me.CurrentRecord <> acFirst Then
DoCmd.GoToRecord , , acPrevious
KeyCode = 0
Else
DoCmd.GoToRecord , , acLast
End If
Case Else

End Select

Thanks!
 
You can simplify this by manipulating the error handling. It is often useful to put Err.Number rather than Err.Description You then know the error you are dealing with. In your case 2105

In the error handling put

Err_Form_KeyDown:
If Err.Number = 2105 Then
Resume Exit_Form_KeyDown
Else
MsgBox Err.Description
Resume Exit_Form_KeyDown
End If

HTH

Dave
 
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Form_KeyDown_Err
Select Case KeyCode
Case vbKeyDown
DoCmd.GoToRecord Record:=acNext
KeyCode = 0
Case vbKeyUp
DoCmd.GoToRecord Record:=acPrevious
KeyCode = 0
Case Else

End Select

Form_KeyDown_Exit:
Exit Sub

Form_KeyDown_Err:
Select Case Err.Number
Case adhcErrInvalidRow
KeyCode = 0
Case Else
MsgBox "Error: " & Err.Description & _
" (" & Err.Number & ")"
End Select
Resume Form_KeyDown_Exit
End Sub
 
Rich said:
DoCmd.GoToRecord Record:=acNext
DoCmd.GoToRecord Record:=acPrevious

And for those who have leaped into the next millennium:

DoCmd.GoToRecord , , acPrevious
DoCmd.GoToRecord , , acNext
:D
 
if i decide to implement this feature in two or three separate is the following method the correct way of doing it rather than typing the same code for the three forms:

- create a new module and paste the code in it
- on the keydown event of each form in the code builder i will type call nameofsub

thx!
 

Users who are viewing this thread

Back
Top Bottom