I am setting up treeview on a form which has not given me any problems. I made one small change and now I am having issues. All I am doing is using an option group with just two options (current user and all users). Current user has an option value of 1 and all users has an option value of 2. All I did was take my treeview code (which was working) and insert it into an IF statement. Seems easy in my head. I am getting an error of 3061 Too Few Parameters. Expected 1.
My code is below. Please help. I have hi-lited the error line (in red) the debugger is stopping on. By the way, I am able to open the query in Access 2007 and get results so there are records matching my criteria.
Private Sub AddAllNodes()
If Me.optCurrUser.OptionValue = 1 Then ' Checking to see which option box is checked.
Dim rst As DAO.Recordset
Dim strStatusNodeKey ' key for this STATUS node
Dim strOldStatusKey As String ' for detecting change in STATUS
' open the recordset
Set rst = CurrentDb.QueryDefs!qryMyTasksCurrUser.OpenRecordset
' loop through the rows in the recordset
rst.MoveFirst
Do Until rst.EOF
strStatusNodeKey = rst!StatusNodeKey
If strStatusNodeKey <> strOldStatusKey Then ' check for change in category
' change in Status-add Status node
Me.tvMyTasks.Nodes.Add Text:=rst!TaskCatName, Key:=strStatusNodeKey
strOldStatusKey = strStatusNodeKey ' remember this as the current key for detecting changes
End If
' now add Client Name node
Me.tvMyTasks.Nodes.Add Relationship:=tvwChild, Relative:=strStatusNodeKey, _
Text:=rst!ClientName, Key:=rst!ClientNameNodeKey
rst.MoveNext ' next record in qeury
Loop
Else
' If option button for "All Users" is selected run this code. It sets up all the nodes
' for all records not closed in tblTaskDetails
Dim rs As DAO.Recordset
Dim stStatusNodeKey ' key for this STATUS node
Dim stOldStatusKey As String ' for detecting change in STATUS
' open the recordset
Set rs = CurrentDb.QueryDefs!qryMyTasksAllUsers.OpenRecordset
' loop through the rows in the recordset
rs.MoveFirst
Do Until rs.EOF
stStatusNodeKey = rs!StatusNodeKey
If stStatusNodeKey <> stOldStatusKey Then ' check for change in category
' change in Status-add Status node
Me.tvMyTasks.Nodes.Add Text:=rs!TaskCatName, Key:=stStatusNodeKey
stOldStatusKey = stStatusNodeKey ' remember this as the current key for detecting changes
End If
' now add Client Name node
Me.tvMyTasks.Nodes.Add Relationship:=tvwChild, Relative:=stStatusNodeKey, _
Text:=rs!ClientName, Key:=rs!ClientNameNodeKey
rs.MoveNext ' next record in qeury
Loop
End If
End Sub
My code is below. Please help. I have hi-lited the error line (in red) the debugger is stopping on. By the way, I am able to open the query in Access 2007 and get results so there are records matching my criteria.
Private Sub AddAllNodes()
If Me.optCurrUser.OptionValue = 1 Then ' Checking to see which option box is checked.
Dim rst As DAO.Recordset
Dim strStatusNodeKey ' key for this STATUS node
Dim strOldStatusKey As String ' for detecting change in STATUS
' open the recordset
Set rst = CurrentDb.QueryDefs!qryMyTasksCurrUser.OpenRecordset
' loop through the rows in the recordset
rst.MoveFirst
Do Until rst.EOF
strStatusNodeKey = rst!StatusNodeKey
If strStatusNodeKey <> strOldStatusKey Then ' check for change in category
' change in Status-add Status node
Me.tvMyTasks.Nodes.Add Text:=rst!TaskCatName, Key:=strStatusNodeKey
strOldStatusKey = strStatusNodeKey ' remember this as the current key for detecting changes
End If
' now add Client Name node
Me.tvMyTasks.Nodes.Add Relationship:=tvwChild, Relative:=strStatusNodeKey, _
Text:=rst!ClientName, Key:=rst!ClientNameNodeKey
rst.MoveNext ' next record in qeury
Loop
Else
' If option button for "All Users" is selected run this code. It sets up all the nodes
' for all records not closed in tblTaskDetails
Dim rs As DAO.Recordset
Dim stStatusNodeKey ' key for this STATUS node
Dim stOldStatusKey As String ' for detecting change in STATUS
' open the recordset
Set rs = CurrentDb.QueryDefs!qryMyTasksAllUsers.OpenRecordset
' loop through the rows in the recordset
rs.MoveFirst
Do Until rs.EOF
stStatusNodeKey = rs!StatusNodeKey
If stStatusNodeKey <> stOldStatusKey Then ' check for change in category
' change in Status-add Status node
Me.tvMyTasks.Nodes.Add Text:=rs!TaskCatName, Key:=stStatusNodeKey
stOldStatusKey = stStatusNodeKey ' remember this as the current key for detecting changes
End If
' now add Client Name node
Me.tvMyTasks.Nodes.Add Relationship:=tvwChild, Relative:=stStatusNodeKey, _
Text:=rs!ClientName, Key:=rs!ClientNameNodeKey
rs.MoveNext ' next record in qeury
Loop
End If
End Sub