J
JGarza
Hi Everyone! I have a Form that I am calling my Taskbar, and on this form I
have a TreeView Control that has a listing of a User a JobNumber and a
FormName. using the System Tables I have been able to get all the names of
the forms and allow certain users to view and open certain Forms.
In My TreeView Control, It lists the user name as the first node the second
would be the job number and job name that the user is allowed to view and
work in and the third node is the actual Form name that the user can open in
that job number.
The Code that I am using is below and I was wondering if there was other
code that I could add into it to open the form itself. And if it is possible
to have a query or form read from a treeview control so that when the user
selects a certain form that it automatically knows what job number it is for.
Function ActiveXCtl0_Fill()
Dim tvwDB As Database
Dim tvwRs As Recordset
Dim vbMsg As Integer
On Error GoTo ActiveXCtl0_Fill_Err
Set tvwDB = CurrentDb()
With Me![ActiveXCtl0]
'Fill Level 1
Set tvwRs = tvwDB.OpenRecordset("SELECT * FROM [CurrentUser];",
dbOpenForwardOnly)
Do Until tvwRs.EOF
.Nodes.Add , , StrConv("Level1" & tvwRs![UserName],
vbLowerCase), tvwRs![UserName]
tvwRs.MoveNext
Loop
tvwRs.Close
'Fill Level 2
Set tvwRs = tvwDB.OpenRecordset("SELECT * FROM [JobsUsers];",
dbOpenForwardOnly)
Do Until tvwRs.EOF
.Nodes.Add StrConv("Level1" & tvwRs![UserName], vbLowerCase),
tvwChild, StrConv("Level2" & tvwRs![JobNumber], vbLowerCase),
tvwRs![JobNumber] & " " & tvwRs![JobName]
tvwRs.MoveNext
Loop
tvwRs.Close
'Fill Level 3
Set tvwRs = tvwDB.OpenRecordset("SELECT * FROM [FormsList];",
dbOpenForwardOnly)
Do Until tvwRs.EOF
.Nodes.Add StrConv("Level2" & tvwRs![JobNumber], vbLowerCase),
tvwChild, , tvwRs![Expr1]
tvwRs.MoveNext
Loop
tvwRs.Close
End With
tvwDB.Close
ActiveXCtl0_Fill_Exit:
Exit Function
ActiveXCtl0_Fill_Err:
Select Case Err.Number
Case 35601 'Element not found
vbMsg = MsgBox(Error$ & "@Possible Causes: You selected a
table/query for a child level which does not correspond to a value from it's
parent level.@", vbOKOnly + vbExclamation, "Run-time Error: " & Err.Number)
Case 35602 'Key is not unique in collection
vbMsg = MsgBox(Error$ & "@Possible Causes: You selected a
non-unique field to link levels.@", vbOKOnly + vbExclamation, "Run-time
Error: " & Err.Number)
Case Else
vbMsg = MsgBox(Error$ & "@@", vbOKOnly + vbExclamation,
"Run-time Error: " & Err.Number)
End Select
Resume ActiveXCtl0_Fill_Exit
End Function
have a TreeView Control that has a listing of a User a JobNumber and a
FormName. using the System Tables I have been able to get all the names of
the forms and allow certain users to view and open certain Forms.
In My TreeView Control, It lists the user name as the first node the second
would be the job number and job name that the user is allowed to view and
work in and the third node is the actual Form name that the user can open in
that job number.
The Code that I am using is below and I was wondering if there was other
code that I could add into it to open the form itself. And if it is possible
to have a query or form read from a treeview control so that when the user
selects a certain form that it automatically knows what job number it is for.
Function ActiveXCtl0_Fill()
Dim tvwDB As Database
Dim tvwRs As Recordset
Dim vbMsg As Integer
On Error GoTo ActiveXCtl0_Fill_Err
Set tvwDB = CurrentDb()
With Me![ActiveXCtl0]
'Fill Level 1
Set tvwRs = tvwDB.OpenRecordset("SELECT * FROM [CurrentUser];",
dbOpenForwardOnly)
Do Until tvwRs.EOF
.Nodes.Add , , StrConv("Level1" & tvwRs![UserName],
vbLowerCase), tvwRs![UserName]
tvwRs.MoveNext
Loop
tvwRs.Close
'Fill Level 2
Set tvwRs = tvwDB.OpenRecordset("SELECT * FROM [JobsUsers];",
dbOpenForwardOnly)
Do Until tvwRs.EOF
.Nodes.Add StrConv("Level1" & tvwRs![UserName], vbLowerCase),
tvwChild, StrConv("Level2" & tvwRs![JobNumber], vbLowerCase),
tvwRs![JobNumber] & " " & tvwRs![JobName]
tvwRs.MoveNext
Loop
tvwRs.Close
'Fill Level 3
Set tvwRs = tvwDB.OpenRecordset("SELECT * FROM [FormsList];",
dbOpenForwardOnly)
Do Until tvwRs.EOF
.Nodes.Add StrConv("Level2" & tvwRs![JobNumber], vbLowerCase),
tvwChild, , tvwRs![Expr1]
tvwRs.MoveNext
Loop
tvwRs.Close
End With
tvwDB.Close
ActiveXCtl0_Fill_Exit:
Exit Function
ActiveXCtl0_Fill_Err:
Select Case Err.Number
Case 35601 'Element not found
vbMsg = MsgBox(Error$ & "@Possible Causes: You selected a
table/query for a child level which does not correspond to a value from it's
parent level.@", vbOKOnly + vbExclamation, "Run-time Error: " & Err.Number)
Case 35602 'Key is not unique in collection
vbMsg = MsgBox(Error$ & "@Possible Causes: You selected a
non-unique field to link levels.@", vbOKOnly + vbExclamation, "Run-time
Error: " & Err.Number)
Case Else
vbMsg = MsgBox(Error$ & "@@", vbOKOnly + vbExclamation,
"Run-time Error: " & Err.Number)
End Select
Resume ActiveXCtl0_Fill_Exit
End Function