tab cycling

G

Guest

I'm making a data entry form
Is it possible to set the tab cycling so that one doesn't have to repeatedly press the tab key to cycle through to the end of a row of text boxes if there are blank fields in a data entry form but I want to go to the next row to enter data

Example
Enter data in several text boxes in a row. Then there are several blanks, and I want to go to the next row to enter new data. Instead of tabbing through the blank text boxes to reach the next row, I want to tab, for example, twice, to get to the next row and enter new data in the new row
 
A

Allen Browne

If your form is in Datasheet view, you can press the Down arrow to move down
a row.

If it is in Continuous view, you can use code to achieve the same result.

1. Paste the code below into a new module (Module tab of the Database
window), and save.

2. Set the KeyPreview property of your form to Yes.

3. Set the On Key Down property to:
[Event Procedure]

4. Click the Build button (...) beside this.
Access opens the code window.

5. Between the "Private Sub ..." and "End Sub" lines, enter:
Call ContinuousUpDown(Me, KeyCode)

-----------------code begins-----------------
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)

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
MsgBox "Error " & Err.Number & ": " & Err.Description
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
MsgBox "Error " & Err.Number & ": " & Err.Description
End If
Resume Exit_ContinuousUpDownOk
End Function
-----------------code ends-----------------

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

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

Roger said:
I'm making a data entry form.
Is it possible to set the tab cycling so that one doesn't have to
repeatedly press the tab key to cycle through to the end of a row of text
boxes if there are blank fields in a data entry form but I want to go to the
next row to enter data?
Example:
Enter data in several text boxes in a row. Then there are several blanks,
and I want to go to the next row to enter new data. Instead of tabbing
through the blank text boxes to reach the next row, I want to tab, for
example, twice, to get to the next row and enter new data in the new row.
 
G

Guest

I got the same results by writing code using the word 'null'. So if the focus is null, it'll just move onto the next control that is programmed in the code.
 

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