Emmulate Datasheet key navigation in Form view

L

Lachlan Sharp

I want to be able to navigate between records in Form view
by using the up and down arrow keys the same as is done in
a forms datasheet view.

The keydown event for my textbox controls looks like this:
' ********
If Me.CurrentView = 1 Then ' When in Form View
Select Case KeyCode
Case 38 ' Arrow Up
If Shift = 0 Then
' If only the arrow key pressed then _
replace keystroke with ctrl+PgeUp
KeyCode = 33 ' Page Up
Shift = 2 ' Ctrl
End If

Case 40 ' Arrow Down
If Shift = 0 Then
' If only the arrow key pressed then _
replace keystroke with ctrl+PgDn
KeyCode = 34 ' Page Down
Shift = 2 ' Ctrl
End If

End Select
End If
' *******

The problem is that I don't seem to be able to change
the 'Shift' value and hence the result is the same as
the 'Page Up' or 'Page Down' keys on their own.

How can I emmulate Ctrl+PgUp and Ctrl+PgDn?

Thanks

Lachlan Sharp
 
A

Allen Browne

Below is what we use to use the up/down arrow keys to move record in a
continuous form.

----------------------------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--------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top