View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Jim Cone[_2_] Jim Cone[_2_] is offline
external usenet poster
 
Posts: 1,549
Default URGENT- Form design and field tab-order problems

"Field" in a broad sense is another name for "Column".
A "Control" is Not a field.
Apparently you have an Excel worksheet with controls on it.
I would assume buttons, listboxes and combo boxes (dropdowns).
You want to move between the controls (in a particular order) using the Tab key?
'--
The following code goes in the module for the sheet with the controls.
It assumes there are 3 controls on the sheet: CommandButton1, ScrollBar1
and ComboBox1. (Every control on a sheet needs the associated "KeyDown"
code - 10 controls needs 10 sets of code in the module.)
For each control the "next" and "previous" control must be entered in the code.
The code come from a post by Rob Bovey in 2003 (with slight modification).
--
Jim Cone
Portland, Oregon USA

'------
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Dim bBackwards As Boolean
Const ctlPrev As String = "CommandButton1"
Const ctlNext As String = "ScrollBar1"

Select Case KeyCode
Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
Application.ScreenUpdating = False
'Determine forwards or backwards
bBackwards = CBool(Shift) 'JBC
'In Excel 97 must select cell before activating another control
If Application.Version < 9 Then ActiveSheet.Range("A1").Select
'Activate the appropriate control based on key(s) pressed
If bBackwards Then
ActiveSheet.OLEObjects(ctlPrev).Activate
Else
ActiveSheet.OLEObjects(ctlNext).Activate
End If
Application.ScreenUpdating = True
End Select
End Sub
'--
Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Dim bBackwards As Boolean
Const ctlPrev As String = "ScrollBar1"
Const ctlNext As String = "ComboBox1"

Select Case KeyCode
Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
Application.ScreenUpdating = False
'Determine forwards or backwards
bBackwards = CBool(Shift) ' JBC
'In Excel 97 must select cell before activating another control
If Application.Version < 9 Then ActiveSheet.Range("A1").Select
'Activate the appropriate control based on key(s) pressed
If bBackwards Then
ActiveSheet.OLEObjects(ctlPrev).Activate
Else
ActiveSheet.OLEObjects(ctlNext).Activate
End If
Application.ScreenUpdating = True
End Select
End Sub
'--
Private Sub ScrollBar1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Dim bBackwards As Boolean
Const ctlPrev As String = "ComboBox1"
Const ctlNext As String = "CommandButton1"

Select Case KeyCode
Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
Application.ScreenUpdating = False
'Determine forwards or backwards
bBackwards = CBool(Shift) ' JBC
'In Excel 97 must select cell before activating another control
If Application.Version < 9 Then ActiveSheet.Range("A1").Select
'Activate the appropriate control based on key(s) pressed
If bBackwards Then
ActiveSheet.OLEObjects(ctlPrev).Activate
Else
ActiveSheet.OLEObjects(ctlNext).Activate
End If
Application.ScreenUpdating = True
End Select
End Sub
'-----------




"Foxcole"
wrote in message
Hello, Jim. Thanks for replying!

What does "create fields from the Control toolbox" mean ?
That statement is completely foreign to me and I have used Excel
for at least a couple of months. Is it something from xl2007 ?


Excel 2003 and as far as I know, at least back to Excel 97... View
Toolbars Control Toolbox.


As far as tabbing from one input cell to another...
The input cells should be set up so the "next" cell is to the
right or below the previous one.


I seem to be having great difficulty creating an accurate picture of
what I'm working with so people can understand the requirements.

I can't sent up input cells so the next cell is adjacent to the
previous one. In this particular document (unlike another I've asked
about in a different thread) I'm not using input cells. I'm trying to
"tab" or, more accurately, control focus from one field to the next in
a prescribed order, when the user hits the Tab key.

These fields or controls are merely sitting on top of a page layout
that the sender created in Excel... which is otherwise a paper form
just like any other paper form, and could be printed and filled out
entirely by hand if the service tech chose to do that.

I have no say in how the form looks or where the fields are located.
The form isn't tied to any worksheet range or database or anything.
It's just a way to put marks on the form page. My understanding is
that these are entirely handled with VBA, so I'm hoping for help
coding how each field looks when it's in focus, and how to pass focus
to the next -- and previous -- field when the user hits Tab.