Treeview problem ,So strange !

X

x6v87qe

hi,everyone. I've got a problem with my treeview control.It's not happed all
the time
but for some of the computers. I used "date" as the node point for the
treeview,when click on a particular date , another subform will display
thecorresponding infor on this date. it works fine on my computer,HOWEVER,in
some other computers, it behavours like this:
1-7/8/2006- no disp, 8/8/2006-ok,9-12/8/2006-no dis, rest -ok
1-8/9/2006- no disp, 9/9/2006-ok,10-12/9/2006-no dis, rest -ok
1-9/10/2006- no disp, 10/10/2006-ok,11-12/10/2006-no dis, rest -ok
1-10/8/2006- no disp, 11/11/2006-ok,12/11/2006-no dis, rest -ok

Isn't it wierd ?!!! Here is my code:
___________________________________________
Sub AddMyTree()
On Error GoTo Err_AddMyTree
Dim conn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim nodCurrent As Node
Dim objTree As Object

Set objTree = Me.TreeView0
Set conn = CurrentProject.Connection

strSQL = "SELECT DISTINCT DateRec FROM Table1 GROUP BY DateRec"

rst.Open strSQL, conn, adOpenStatic, adLockReadOnly

Do While Not rst.EOF
Set nodCurrent = objTree.Nodes.Add(, , "a" & rst("DateRec"),
rst("DateRec"), 1, 2)
nodCurrent.Tag = rst("DateRec")
rst.MoveNext
Loop



rst.Close
Set rst = Nothing
Set conn = Nothing

Exit_AddMyTree:
Exit Sub

Err_AddMyTree:
Set rst = Nothing
Set conn = Nothing
MsgBox Err.Description, vbCritical, "AddMyTree"
Resume Exit_AddMyTree

End Sub

Private Sub Detail_Click()

End Sub

Private Sub TreeView0_NodeClick(ByVal Node As Object)
Dim strSQL As String
strSQL1 = "SELECT * FROM Table1 "
strSQL = strSQL1 & "WHERE DateRec = # " & CDate(Node.Tag) & " # "

Me.Table1_subform.Form.RecordSource = strSQL
Me.Table1_subform.Form.Requery

End Sub


Private Sub Form_Load()

AddMyTree

End Sub
__________________________________________

Can any body tell me what may be the problem ? I been struglling this for
days .
and
if possible can any one give me an example on how to make the treeview to be
displayed on a "year","Month","date" ,three levels grade, currently it just
displayed all the dates in the same manner

Many thanks !
 
X

x6v87qe

Great !! thanks Jamie! ,bothe of the way works, but how should I modeify the

Click even to make it possible to be displayed on a subform

Private Sub TreeView0_NodeClick(ByVal Node As Object)
Dim strSQL As String
strSQL1 = "SELECT * FROM Table1 "
strSQL = strSQL1 & "WHERE DateRec = # " & CDate(Node.Tag) & " # "

Me.Table1_subform.Form.RecordSource = strSQL
Me.Table1_subform.Form.Requery

End Sub

this won't work please help
 
X

x6v87qe

Great Jamie ! both the way works. How can I modeify the click procedure to
make it displayed on the ssub form

Private Sub TreeView0_NodeClick(ByVal Node As Object)
Dim strSQL As String
strSQL1 = "SELECT * FROM Table1 "
strSQL = strSQL1 & "WHERE DateRec = # " & CDate(Node.Tag) & " # "

Me.Table1_subform.Form.RecordSource = strSQL
Me.Table1_subform.Form.Requery

End Sub

This just not woking,please help
 
X

x6v87qe

Hi,Jamie
I did as u said it, comes out an error "Invild or unquantified reference" ?
for .Fields
Please also tell me how to write the click event, I coy that code form
aomewhere else. I have no idea of that at all. Thanks

"Private Sub TreeView0_NodeClick(ByVal Node As Object)
Dim strSQL As String
strSQL = "SELECT * FROM FinalQuery "
strSQL = strSQL & "WHERE Daterec = #" & CDate(Node.Tag) & "# "

Me.FinalQuery_subform.Form.RecordSource = strSQL
Me.FinalQuery_subform.Form.Requery
End Sub"
 
X

x6v87qe

Thanks for your reply ,Jamie. ! Sorry, I thought I may misguid you. The
problem I have was : don't know how to write the code in
"TreeView0_NodeClick" .Treeview was fine ,but when I click the on the node.
it always comes "Type mismatch". This is the code I have :
_____________________________________
Option Compare Database

Sub AddMyTree()
On Error GoTo Err_AddMyTree
Dim conn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim strSQL As String
Dim nodCurrent As Node
Dim objTree As Object

Set objTree = Me.TreeView0
Set conn = CurrentProject.Connection

strSQL = "SELECT DISTINCT DateRec FROM FinalQuery GROUP BY DateRec;"

rst.Open strSQL, conn, adOpenStatic, adLockReadOnly


Dim nodeYear As Node
Dim nodeYearMonth As Node

Do While Not rst.EOF
Set nodeYear = Nothing
On Error Resume Next
Set nodeYear = objTree.Nodes _
("a" & Format(rst("DateRec").Value, "yyyy"))
On Error GoTo Err_AddMyTree
If nodeYear Is Nothing Then
Set nodeYear = objTree.Nodes _
.Add(, , "a" & Format(rst("DateRec").Value, "yyyy"), _
Format(rst("DateRec").Value, "yyyy"), 1, 2)

End If

Set nodeYearMonth = Nothing
On Error Resume Next
Set nodeYearMonth = objTree.Nodes _
("a" & Format(rst("DateRec").Value, "yyyymm"))
On Error GoTo Err_AddMyTree
If nodeYearMonth Is Nothing Then
Set nodeYearMonth = objTree.Nodes _
.Add(nodeYear, tvwChild, _
"a" & Format(rst("DateRec").Value, "yyyymm"), _
Format(rst("DateRec").Value, "mmmm"), 1, 2)
End If

Set nodCurrent = objTree.Nodes _
.Add(nodeYearMonth, tvwChild, _
"a" & rst("DateRec").Value, _
rst("DateRec").Value, 1, 2)
nodCurrent.Tag = rst.Fields("DateRec").Value

rst.MoveNext

Loop




rst.Close
Set rst = Nothing
Set conn = Nothing

Exit_AddMyTree:
Exit Sub

Err_AddMyTree:
Set rst = Nothing
Set conn = Nothing
MsgBox Err.Description, vbCritical, "AddMyTree"
Resume Exit_AddMyTree

End Sub



Private Sub Detail_Click()

End Sub

Private Sub TreeView0_NodeClick(ByVal Node As Object)
Dim strSQL As String
strSQL = "SELECT * FROM FinalQuery "
strSQL = strSQL & "WHERE Daterec = #" & CDate(Node.Tag) & "# "

Me.FinalQuery_subform.Form.RecordSource = strSQL
Me.FinalQuery_subform.Form.Requery
End Sub



Private Sub Form_Load()
AddMyTree
End Sub
_____________________________________
 
X

x6v87qe

My dear GOD !!! still not working, This time no error messege come out ,but
the sub form was not querying at all.

That's what I have
________
Set nodCurrent = objTree.Nodes _
..Add(nodeYearMonth, tvwChild, _
"a" & rst("DateRec").Value, _
rst("DateRec").Value, 1, 2)
nodCurrent.Tag = Format$(rst.Fields("DateRec").Value, "yyyy-mm-dd ')
___________

____

Private Sub TreeView0_NodeClick(ByVal Node As Object)
Dim strSQL As String
strSQL = "SELECT * FROM FinalQuery "
strSQL = strSQL & "WHERE Daterec = #" & CDate(Node.Tag) & "# "

Me.FinalQuery_subform.Form.RecordSource = strSQL
Me.FinalQuery_subform.Form.Requery
End Sub
_____

Jamie, would you be kind enough to paste a full code ? I almost dead of it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top