Set Down Arrow Action In Microsoft Access

390 pts.
Tags:
Access forms
Microsoft Access
Microsoft Access forms
Hi, I was wondering if there was a way to set when the down arrow is pressed on a Continuous Form in access that it goes to the next record and not the next field. Any suggestions would be great. Thanks, Dustin

Answer Wiki

Thanks. We'll let you know when a new response is added.

Dustin’s original answer was a great start, but didn’t handle the first and last records in a form. With a bit of help I got to this:

‘Put an accurate record counter right at the start of the form’s module,
‘ after the Option Compare Database and Option Explicit statements

Public FormRecCount As Integer

‘Update the accurate record counter anytime it might change
‘ Thanks to Martin Green at http://www.fontstuff.com/mailbag/qaccess04.htm

Private Sub Form_Current()
Dim rst As Object
Set rst = Me.RecordsetClone
On Error Resume Next
rst.MoveLast
On Error GoTo 0
FormRecCount = rst.Recordcount
End Sub

‘Tell form to check each keystroke as per Dustin’s answer

Private Sub Form_Load()
Me.KeyPreview = True
End Sub

‘Check each keystroke as per Dustin’s answer but only move to previous/next
‘ if not the first/last record. Cancel keystroke if it is.
‘ Thanks to westconn1 and coolsid for KeyCode = 0 to cancel
‘ http://www.vbforums.com/showthread.php?t=543543

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error Resume Next
Select Case KeyCode
Case vbKeyDown
‘ Go to the next record
If Me.CurrentRecord = FormRecCount Then
KeyCode = 0
Else
DoCmd.GoToRecord , , acNext
End If
Case vbKeyUp
‘ Go to the previous record
If Me.CurrentRecord = 1 Then
KeyCode = 0
Else
DoCmd.GoToRecord , , acPrevious
End If
End Select
End Sub

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • RoadDust
    Thanks for posting the answer. Sean
    0 pointsBadges:
    report
  • MikiE
    Could you tell me if this code would be the same if you wanted the enter button to go down records and the right arrow to still go across in a form? (say if I replaced "KeyUp" with "Enter") cheers M
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following