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

Move to next record with Up Arrow or Down Arrow on form. 1

Status
Not open for further replies.

ordendelfai

Technical User
Nov 8, 2002
187
US
I have a continuous form that displays six fields from left to right. It almost looks like excel cells because of the continuous effect. I want the user to be able to click in one of the fields and use the up and down arrows to scroll through the records. I understand that the GoToRecord method already keeps the focus on the same field, so I think I am ok in that respect, but I cannot figure out how to get the code working (and what form event to put it on).

So far I have tried with no success:

~~~~~~~~~~~~~~~~~~~~~~code~~~~~~~~~~~~~~~~~~~~

Private Sub Form_KeyPress(KeyAscii As Integer)
Dim UpArrow As Integer
Dim DOWNArrow As Integer

UpArrow = vbKeyUp
DOWNArrow = vbKeyDown

If UpArrow Then
DoCmd.GoToRecord , , acNext
ElseIf DOWNArrow Then
DoCmd.GoToRecord , , acPrevious
End If
End Sub

Thanks for you help =D

~Orden
 
I think PageUp/Page down keys have the effect you want. Why not train the users to use them?
 
Page Up seems to go one visible page at a time for me on my continuous form, and my users are picky...heh.

If anyone knows, please help ;)
 
First you need to enable Key Preview on your form. Set it to "Yes" in the property window of your form. Then create a procedure in the form's module that looks something like this:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

On Error GoTo Err_KeyDown
Select Case KeyCode
Case vbKeyDown
DoCmd.GoToRecord, , acNext
Case vbKeyUp
DoCmd.GoToRecord, , acPrevious
Case Else
'do nothing at all
End Select

Exit_Err_KeyDown:
Exit Sub

Err_KeyDown:
If Err.Number = 2105 Then
KeyCode = 0
Else
MsgBox Err.Description
End If
Resume Exit_Err_KeyDown

End Sub[/code]

Give that a try...

Ken S.
 
Sorry for the duplicate post, but here it is again with the code tags properly inserted...

-----------------------

First you need to enable Key Preview on your form. Set it to "Yes" in the property window of your form. Then create a procedure in the form's module that looks something like this:

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

On Error GoTo Err_KeyDown
Select Case KeyCode
     Case vbKeyDown
          DoCmd.GoToRecord, , acNext
     Case vbKeyUp
          DoCmd.GoToRecord, , acPrevious
     Case Else
          'do nothing at all
End Select

Exit_Err_KeyDown:
     Exit Sub

Err_KeyDown:
     If Err.Number = 2105 Then
          KeyCode = 0
          Else
               MsgBox Err.Description
     End If
     Resume Exit_Err_KeyDown

End Sub

Give that a try...

Ken S.
 
You my friend are the man ;o). That worked perfectly. As another tip to anyone who might visit this thread, I also set the options for the database to make the right and left arrow move from field to field instead of moving the cursor in the field.

Now this continuous form operates similar to an excel sheet with cells, and the user can arrow to the left, right, or up and down. As the user is moving the arrows, I have a subform that is linked to the continuous form, and changes data with each record. This is a cool feature because before the user had to use his/her mouse to navigate between the different records on the continuous form to see that data change in the subform.

Star for you ken ;o)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top