Down arrow --> next record

J

Joe Holzhauer

I'm working with a continuous form and I'd like the down arrow to
automatically move the user to the next record. Is there a way other than
using the KeyDown, etc. events to do this?

TIA,
Joe
 
J

Joe Holzhauer

Also, is there a way to programmatically move to a new record? The
Form.NewRecord property is read only & I can't find a way to do it, even
using the Form.Recordset.

Thanks!
Joe
 
D

Dirk Goldgar

Joe Holzhauer said:
I'm working with a continuous form and I'd like the down arrow to
automatically move the user to the next record. Is there a way other
than using the KeyDown, etc. events to do this?

I can't think of one offhand..
 
A

Allen Browne

Joe Holzhauer said:
I'm working with a continuous form and I'd like the down arrow to
automatically move the user to the next record. Is there a way other than
using the KeyDown, etc. events to do this?

Unless you switch to Datasheeet view, KeyDown is the only solution.

The code below is designed to go into a standard module, so you can call it
from any continuous form's KeyDown event like this:
Call ContinuousUpDown(Me, KeyCode)

If moves record only if the active control is in the Detail section (not the
Form Header or Form Footer), and only if the text box is not multi-line (has
scrollbar or EnterKeyBehavior set). The case it does not handle is where you
have dropped a combo down and up/down should move up/down the items in the
combo rather than moving record in the form. If you want to handle that case
as well, this link could be helpful:
Determining Combobox's Dropped state
at:
http://www.mvps.org/access/api/api0052.htm

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

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