Complex Form interaction advise needed...

MagicMan

Registered User.
Local time
Yesterday, 23:00
Joined
Aug 28, 2008
Messages
186
I am looking for the best approach to a complex set of forms and their interaction.

Environment:
Microsoft Access 2007 ... Jet Be (at the moment)

Main Form
Recordsource is TxnHdr (Transaction Header) key is TxnID

Subform
Recordsource is TxnDtl (Txn Detail) Linked by TxnID .. Key is TxnID/LineNo
The Subform is Continuous Form with data entry via a ComboBox in the Subform Form Header.

Both the Form and Subform have Keys set to yes and a Form_KeyDown Event which checks every key/key combination for valid keys. This cripples all Access Hotkey's and performs specific Public Subs in the Mainform, when a specific Function Key is pressed, when the focus is in either the Mainform or Subform.

When I press PF7 when the focus is on either the Mainform or Subform the Form_KeyDown Event is triggered which on Case vbKeyF7 processes the Mainform Public Sub OpenLookup_Click. There is a command button on the Mainform and the Click Event also performs this routine.
Code:
....in the MainForm
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode    ' Evaluate Keycode.
        ... more code
        Case vbKeyF7
            OpenLookup_Click
            KeyCode = 0
        ... more code
    End Select
End Sub
 
...in the SubForm
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode    ' Evaluate Keycode.
        ... more code
        Case vbKeyF7
            Me.Parent.OpenLookup_Click
            KeyCode = 0
        ... more code
    End Select
End Sub
 
,,,in the MainForm
Public Sub OpenLookup_Click() ' F7  Lookup 
    DoCmd.OpenForm "Lookup", , , , , acDialog
    Form!TxnDtl.SetFocus
    Form!TxnDtl!cboDataInput.SetFocus
End Sub

On the Lookup Form: (Popup)
The user performs a lookup and if desired presses a command button to add the data found in the lookup to the Subform as a new add. Here is that command button.

Code:
Private Sub Command72_Click()
Dim strData As String
strData = Me.Data
TempVars("NewData") = strData
DoCmd.Close acForm, "Lookup"
End Sub

On return to the Subform, the control is returned to the last field that had focus...cboDataInput. The GotFocus Event triggers and the new data item from the lookup populates the combobox and the combobox After Update is processed as you can see in the following code.
Code:
Private Sub cboDataInput_GotFocus()
    If Nz(TempVars!NewData, 0) > 0 Then
        Me.cboDataInput = TempVars!NewData
        TempVars("NewData") = Null
        cboDataInput_AfterUpdate
    End If
End Sub


As you can see, this works, but is it the best way to achieve the results?

(I would post the code for the forms but in total is is over 1000 lines of code, which I am sure you do not want to muddle thru.)

Any comments are appreciated.
Smiles
Bob
 
Last edited:
On further testing, I find this works for the command button click and pressing my hotkey (PF7) when the focus is in the Mainform but does not work when pressing my hotkey (PF7) when the focus is in the subform.....now I do need some help.
Smiles
Bob
PS: When single stepping through, everything is processed the same way with the exception of the GotFocus (last step). I tried setting focus to a field in the main form from the subform Case prior to openning the popup...no difference.
 

Users who are viewing this thread

Back
Top Bottom