tags:

views:

532

answers:

1

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
A: 

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
CodeSlave
okay i use F6 to go from subform to main form but pressing F6 does 2 things.1) it moves focus to main form2) then it's as if F6 is pressed twice, that is, focus goes to option group (without any event procedure, F6 does move focus to option group) i don't want #2 to happen
same with going from subone to subtwo (yes they are siblings)event procedure keydown case select F5 does two things:1) move focus to subtwo2) move focus to record number on the bottom of form (don't want this to be triggered)
F5? F6? When did they become part of the question??? Have you added this code to an event (like OnLostFocus or OnExit)? And if so, which ones. Perhaps even give us the code for those events.
CodeSlave
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 SelectEnd Sub
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 SelectEnd Sub
never thought of that.. ok i will try setting the keycode variable.it is a global variable? so when i change the value of the keycode variable inside the form_keydown function, it will also change it outside the context of this function?
Ok tried it. and it works. thanks.. that's what i wanted the program to do