1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| Private Sub tvSB_NodeClick(ByVal Node As Object)
'User clicked a node
Dim strSwitchboard_SubForm_ToShow As String
Dim strForm_OpenArgs As String
'The default form to be loaded into the subform-area - if no other will be set within this sub
strSwitchboard_SubForm_ToShow = mconMainForm
'Default: no contents for information being pulled from a form loaded into the subform
mstrFormArgs = ""
'This statement should actually never evaluate to false, it's rather meant to further
'describe the usage of the Split()-function
If UBound(Split(Node.Key, ";")) = 3 Then
Dim strObjectType As String
Dim strObjectName As String
Dim strObjectAddtnl As String
strObjectType = Split(Node.Key, ";")(1) 'second argument within the node's key
strObjectName = Split(Node.Key, ";")(2) 'third argument within the node's key
strObjectAddtnl = Split(Node.Key, ";")(3)
'strObjectAddtnl = Node.Parent & strObjectAddtnl
'strObjectAddtnl = Node.Parent.Parent & strObjectAddtnl
'strObjectAddtnl = Node.Parent.Parent.Parent & strObjectAddtnl
'strObjectAddtnl = Split(Node.Parent.Key, ";")(3) & strObjectAddtnl
'strObjectAddtnl = Split(Node.Parent.Parent.Key, ";")(3) & strObjectAddtnl
On Error Resume Next
Select Case strObjectType
Case "Form"
'Just pass on the form's name - this will result in the switchboard's subform
'being set to this form.
strSwitchboard_SubForm_ToShow = strObjectName
mstrFormArgs = strObjectAddtnl
Case "Form_Dialog"
'Load a form separately
DoCmd.OpenForm FormName:=strObjectName, windowmode:=acDialog, OpenArgs:=strObjectAddtnl
Case "Report"
'This is just a sample call to a report - you might want to distinguish
'between printing directly or showing the preview here.
DoCmd.OpenReport reportname:=strObjectName ', OpenArgs:=strObjectAddtnl '<-- OpenArgs are possible for reports starting with Access 2002 only!
Case "Code"
'For the sake of the sample, this call references a sub within the switchboard-form's
'module (hence the CodeContextObject - this could as well be <Me>).
'An alternative would be to call a function within a general module - in order to do so,
'you'll have to know that module's name (or index). The call would then look like this:
' CallByName modules(0), strObjectName, VbMethod
'or
' CallByName modules("mdl_SomeModule"), strObjectName, VbMethod
CallByName CodeContextObject, strObjectName, VbMethod, strObjectAddtnl
Case ""
'do nothing (user clicked a parent-node)
Case Else
'Unrecognized "Ojbect-Type" - show an error-message
MsgBox "Unknown Object-Type within Switchboard-table: " & strObjectType, vbExclamation, "Error"
End Select
End If
If Me!Switchboard_Subform.SourceObject <> strSwitchboard_SubForm_ToShow Then
'If this sub resulted in a different form to be shown in the subform-area, load it
Me!Switchboard_Subform.SourceObject = strSwitchboard_SubForm_ToShow
End If
If Err.Number <> 0 Then
'For debugging-purposes, I suggest adding a message like this.
'
'For the sample, I'm only providing one form
MsgBox "This would result in a " & strObjectType & " called " & Q & strObjectName & Q & " being called," & vbCrLf & _
"but calling the object raised an exception (that object probably just doesn't exist).", _
vbInformation, "Error/bug: (Node-click)"
End If
If strSwitchboard_SubForm_ToShow <> mconMainForm Then
'Attempt to have a potentially loaded form refresh its information;
'In order for this to be successful, the subform will have to provide a public sub called "RefreshInfo"
Err.Clear
Switchboard_Subform.Form.RefreshInfo
End If
End Sub |