A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Using 'UP' & 'DOWN' arrow keys



 
 
Thread Tools Display Modes
  #1  
Old June 9th, 2004, 02:21 PM
arm
external usenet poster
 
Posts: n/a
Default Using 'UP' & 'DOWN' arrow keys

Hello,

Could anyone please help me. Whenever I wanted to move to the next or
previous record in a continuous form I always use CTRL PAGEDN or CTRL
PAGEUP key combination. Is there anyway to make the DOWN ARROW and UP
ARROW keys to do the same? Thanks.


  #2  
Old June 9th, 2004, 02:32 PM
Allen Browne
external usenet poster
 
Posts: n/a
Default Using 'UP' & 'DOWN' arrow keys

Below are the two functions that we use with our continous forms. Paste them
into a standard module (Modules tab of Database window). Then in any
continuous form set these properties for the form:
Key Preview Yes
On Key Down [Event Procedure]

Click the Build button beside the On Key Down property.
Access opens the Code window.
Paste this line into the event procedu
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Call ContinuousUpDown(Me, KeyCode)
End Sub

The code responds to the Up/Down keystroke only if the control is in the
detail section of the form, and only if the control does not look like a a
multi-line control (because it has a scroll bar, or the EnterKeyBehavior is
multi-line).

The code explicitly saves any uncommitted edits (as there are bugs
associated with trying to move records with unsaved edits), and ignores the
errors of trying to move above the first or past the new record.

Replace the error handler call with your own, or if you want ours you can
grab it from he
http://allenbrowne.com/ser-23a.html

Hope that helps.

-------------code starts---------------------
Public Sub ContinuousUpDown(frm As Form, KeyCode As Integer)
On Error GoTo Err_ContinuousUpDown
'Purpose: Respond to Up/Down in continuous form, by moving record,
' unless the active control's EnterKeyBehavior is on.
'Usage: Call ContinuousUpDown(Me, KeyCode)
Dim sForm As String

sForm = frm.Name

Select Case KeyCode
Case vbKeyUp
If ContinuousUpDownOk Then
'Save any edits
If frm.Dirty Then
RunCommand acCmdSaveRecord
End If
'Go previous: error if already there.
RunCommand acCmdRecordsGoToPrevious
KeyCode = 0 'Destroy the keystroke
End If

Case vbKeyDown
If ContinuousUpDownOk Then
'Save any edits
If frm.Dirty Then
frm.Dirty = False
End If
'Go to the next record, unless at a new record.
If Not frm.NewRecord Then
RunCommand acCmdRecordsGoToNext
End If
KeyCode = 0 'Destroy the keystroke
End If
End Select

Exit_ContinuousUpDown:
Exit Sub

Err_ContinuousUpDown:
Select Case Err.Number
Case 2046, 2101, 2113, 3022, 2465 'Already at first record, or save
failed, or The value you entered isn't valid for this field.
KeyCode = 0
Case Else
Call LogError(Err.Number, Err.Description, "ContinuousUpDown()",
"Form = " & sForm)
End Select
Resume Exit_ContinuousUpDown
End Sub
Private Function ContinuousUpDownOk() As Boolean
On Error GoTo Err_ContinuousUpDownOk
'Purpose: Suppress moving up/down a record in a continuous form if:
' - control is not in the Detail section, or
' - multi-line text box (vertical scrollbar, or
EnterKeyBehavior true).
'Usage: Called by ContinuousUpDown.
Dim bDontDoIt As Boolean
Dim ctl As Control

Set ctl = Screen.ActiveControl
If ctl.Section = acDetail Then
If TypeOf ctl Is TextBox Then
bDontDoIt = ((ctl.EnterKeyBehavior) Or (ctl.ScrollBars 1))
End If
Else
bDontDoIt = True
End If

Exit_ContinuousUpDownOk:
ContinuousUpDownOk = Not bDontDoIt
Set ctl = Nothing
Exit Function

Err_ContinuousUpDownOk:
If Err.Number 2474 Then 'There's no active control
Call LogError(Err.Number, Err.Description, conMod &
"ContinuousUpDownOk()")
End If
Resume Exit_ContinuousUpDownOk
End Function
-------------code ends---------------------
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"arm" wrote in message
...

Could anyone please help me. Whenever I wanted to move to the next or
previous record in a continuous form I always use CTRL PAGEDN or

CTRL
PAGEUP key combination. Is there anyway to make the DOWN ARROW and

UP
ARROW keys to do the same? Thanks.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:51 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.