rtochip
rtochip

Reputation:

moving focus from subform to main form

i have main form MAINF and two subforms SUBONE and SUBTWO

I want to be able to move focus (cursor) between them.

From MAINF to SUBONE or SUBTWO, I can call Me![SUBONE].SetFocus or Me![SUBTWO].SetFocus. This seems to work.

BUT:

1) From SUBONE to SUBTWO, I have no idea. what is the correct way of programatically moving focus?

2) From SUBONE to one of MAINF's control say "Customer ID", how do i do it?

Edit: Here's the code that rtochip provided.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyF5
            Me.Parent![Item - Order Subform].SetFocus
            DoCmd.GoToControl "Supplier ID NUM"
        Case vbKeyF6 
            Me.Parent.[Item ID].SetFocus
    End Select
End Sub    

Upvotes: 2

Views: 12354

Answers (1)

BIBD
BIBD

Reputation: 15384

If SUBTWO is a child of SUBONE, then it's the same way. However, if they are siblings thenyou have to reference it as an object on the parent first.

There are two ways to reference objects on your parent:

  1. You can reference the parent
    Me.Parent.[Customer ID].SetFocus
    (btw, change than control's name to Customer_ID - it makes it easier to use, and you won't require the []'s)

  2. You can reference it directly
    Forms!MAINF.[Customer ID].SetFocus

Update: The KeyDown event is probably being caught later on the main form. You could always clear it out before you finish with moving focus.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyF5
            Me.Parent![Item - Order Subform].SetFocus
            DoCmd.GoToControl "Supplier ID NUM"
            KeyCode = 0  'Trap F5
        Case vbKeyF6
            Me.Parent.[Item ID].SetFocus
            keyCode = 0  'Trap F6
    End Select
    'keyCode = 0    'Note: you can't do it here because it will trap ALL your
                    'KeyCodes. Not just F5 and F6.
End Sub

Upvotes: 1

Related Questions