Move from 1 subfrm into another subfrm using key down in access 20

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can anyone suggest how to move from 1 subfrm into another subfrm using a key
stroke? I have tried to set up a macro but have failed. Got lost in help can
anyone suggest solution?
greatly appreciated in advance
Michael
 
according to the KeyDown Event topic in Access Help:

"You can use a KeyDown or KeyUp macro to respond whenever the user presses
or releases a key while a form or control has the focus. However, macros
can't return the key code and determine which key was pressed, so *you
typically use event procedures* with these events."

in design view of the "first" subform, set the form's KeyPreview property to
Yes. then double click on the OnKeyDown event line. the words [Event
Procedure] will appear. click on the Build button at the right (...), the
VBA Editor window will open with an event already created. you'll see this

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

End Sub

paste the following code in the blank line between the beginning and ending
lines of the sub procedure, as

If KeyCode = vbKey1 And (Shift And acAltMask) > 0 Then
Me.Parent!Child2.SetFocus
End If

substitute the name of the "second" subform control for "Child2". note:
make sure you use the name of the subform *control*, rather than the name of
the subform object (that's the name you see in the database window).
sometimes the two names are the same, sometimes different. to get the name
of the subform control, open the main form in design view. click once on the
second subform (within the main form) to select it. in the Properties box,
click the Other tab, and look at the Name property.

open the main form in form view. when you're in the first subform, press
Alt+1 (don't use the number pad, use the "1" key above the letter Q.) the
focus should move to your second subform.

you can use a different key, rather than the "1", and use Ctrl or Shift
instead of Alt, if you want. see the KeyDown Event topic in Access Help, for
details on how to change those values in the above code. post back if you
run into problems.

hth
 
Michael,

An alternative to Tina's excellent suggestion, is to use an AutoKeys
macro. Mind you, Tina's example of Alt-1 wouldn't be possible, because
Alt is not supported by AutoKeys, but you could do Ctrl-1. Make a new
macro, and in the Macro Name column of the macro design window (if you
can't see a Macro Name column, select it from the View menu), type ^1
and then in the Action column use the GoToControl action.
 
thanks for the plug, Steve <g> and you're right, i should have outlined
the AutoKeys option, too. btw, haven't done macros in quite a while; is
there a way to make an autokeys action "form specific"? thx, tina :)


Steve Schapel said:
Michael,

An alternative to Tina's excellent suggestion, is to use an AutoKeys
macro. Mind you, Tina's example of Alt-1 wouldn't be possible, because
Alt is not supported by AutoKeys, but you could do Ctrl-1. Make a new
macro, and in the Macro Name column of the macro design window (if you
can't see a Macro Name column, select it from the View menu), type ^1
and then in the Action column use the GoToControl action.

--
Steve Schapel, Microsoft Access MVP

according to the KeyDown Event topic in Access Help:

"You can use a KeyDown or KeyUp macro to respond whenever the user presses
or releases a key while a form or control has the focus. However, macros
can't return the key code and determine which key was pressed, so *you
typically use event procedures* with these events."

in design view of the "first" subform, set the form's KeyPreview property to
Yes. then double click on the OnKeyDown event line. the words [Event
Procedure] will appear. click on the Build button at the right (...), the
VBA Editor window will open with an event already created. you'll see this

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

End Sub

paste the following code in the blank line between the beginning and ending
lines of the sub procedure, as

If KeyCode = vbKey1 And (Shift And acAltMask) > 0 Then
Me.Parent!Child2.SetFocus
End If

substitute the name of the "second" subform control for "Child2". note:
make sure you use the name of the subform *control*, rather than the name of
the subform object (that's the name you see in the database window).
sometimes the two names are the same, sometimes different. to get the name
of the subform control, open the main form in design view. click once on the
second subform (within the main form) to select it. in the Properties box,
click the Other tab, and look at the Name property.

open the main form in form view. when you're in the first subform, press
Alt+1 (don't use the number pad, use the "1" key above the letter Q.) the
focus should move to your second subform.

you can use a different key, rather than the "1", and use Ctrl or Shift
instead of Alt, if you want. see the KeyDown Event topic in Access Help, for
details on how to change those values in the above code. post back if you
run into problems.
 
Might be able to do it using the Condition column, testing for the form name
that is "active" (has the focus ... Screen.ActiveForm.Name) perhaps?
haven't tried this.

--

Ken Snell
<MS ACCESS MVP>

tina said:
thanks for the plug, Steve <g> and you're right, i should have outlined
the AutoKeys option, too. btw, haven't done macros in quite a while; is
there a way to make an autokeys action "form specific"? thx, tina :)


Steve Schapel said:
Michael,

An alternative to Tina's excellent suggestion, is to use an AutoKeys
macro. Mind you, Tina's example of Alt-1 wouldn't be possible, because
Alt is not supported by AutoKeys, but you could do Ctrl-1. Make a new
macro, and in the Macro Name column of the macro design window (if you
can't see a Macro Name column, select it from the View menu), type ^1
and then in the Action column use the GoToControl action.

--
Steve Schapel, Microsoft Access MVP

according to the KeyDown Event topic in Access Help:

"You can use a KeyDown or KeyUp macro to respond whenever the user presses
or releases a key while a form or control has the focus. However,
macros
can't return the key code and determine which key was pressed, so *you
typically use event procedures* with these events."

in design view of the "first" subform, set the form's KeyPreview property to
Yes. then double click on the OnKeyDown event line. the words [Event
Procedure] will appear. click on the Build button at the right (...), the
VBA Editor window will open with an event already created. you'll see this

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

End Sub

paste the following code in the blank line between the beginning and ending
lines of the sub procedure, as

If KeyCode = vbKey1 And (Shift And acAltMask) > 0 Then
Me.Parent!Child2.SetFocus
End If

substitute the name of the "second" subform control for "Child2". note:
make sure you use the name of the subform *control*, rather than the name of
the subform object (that's the name you see in the database window).
sometimes the two names are the same, sometimes different. to get the name
of the subform control, open the main form in design view. click once
on the
second subform (within the main form) to select it. in the Properties box,
click the Other tab, and look at the Name property.

open the main form in form view. when you're in the first subform,
press
Alt+1 (don't use the number pad, use the "1" key above the letter Q.) the
focus should move to your second subform.

you can use a different key, rather than the "1", and use Ctrl or Shift
instead of Alt, if you want. see the KeyDown Event topic in Access
Help, for
details on how to change those values in the above code. post back if you
run into problems.
 
Back
Top