Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / November 2006

Tip: Looking for answers? Try searching our database.

Problem with Tree View

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kerry_ja@yahoo.com - 08 Nov 2006 17:49 GMT
Hi all,

I hope someone can help me.

I am trying to use a tree control, and am not very familiar with them.
I used one successfully in one database, but when I try to use the
same form in a different database, I get problems.  Below is the code
for the form.  (I basically just copied the code from Microsoft
http://support.microsoft.com/kb/209891).  When I try to compile the
database, I get a userdefined type not defined error.  This happens on
the statement Dim nodCurrent As Node.   I know that Microsoft said I
need Microsoft DAO 3.6 Object Library, and I do have a reference to
that in the database.

Private Sub Form_Load()
   Const strTableQueryName = "qryCategoryCode"
   Dim db As DAO.Database, rst As DAO.Recordset
   Set db = CurrentDb
   Set rst = db.OpenRecordset(strTableQueryName, dbOpenDynaset,
dbReadOnly)
   AddBranch rst:=rst, strPointerField:="Parent", strIDField:="Label",
strTextField:="Description"
End Sub

'================= AddBranch Sub Procedure ======================
'      Recursive Procedure to add branches to TreeView Control
'Requires:
'   ActiveX Control:  TreeView Control
'              Name:  xTree
'Parameters:
'               rst:  Self-referencing Recordset containing the data
'   strPointerField:  Name of field pointing to parent's primary key
'        strIDField:  Name of parent's primary key field
'      strTextField:  Name of field containing text to be displayed
'=============================================================
Sub AddBranch(rst As Recordset, strPointerField As String, _
             strIDField As String, strTextField As String, _
             Optional varReportToID As Variant)
  On Error GoTo errAddBranch
  Dim nodCurrent As Node, objTree As TreeView
  Dim strCriteria As String, strText As String, strKey As String
  Dim nodParent As Node, bk As String
  Set objTree = Me!treCategoryCode.Object
  If IsMissing(varReportToID) Then  ' Root Branch.
     strCriteria = "Len(" & strPointerField & ")=0"
  Else  ' Search for records pointing to parent.
     strCriteria = BuildCriteria(strPointerField, _
          rst.Fields(strPointerField).Type, "=" & varReportToID)
     Set nodParent = objTree.Nodes("a" & varReportToID)
  End If

     ' Find the first root node.
  rst.FindFirst strCriteria
  Do Until rst.NoMatch
        ' Create a string with LastName.
     strText = rst(strTextField)
     strKey = "a" & rst(strIDField)
     If Not IsMissing(varReportToID) Then  'add new node to the parent
        Set nodCurrent = objTree.Nodes.Add(nodParent, tvwChild,
strKey, strText)
     Else    ' Add new node to the root.
        Set nodCurrent = objTree.Nodes.Add(, , strKey, strText)
     End If
        ' Save your place in the recordset so we can pass by ref for
speed.
     bk = rst.Bookmark
        ' Add children who report to this node.
     AddBranch rst, strPointerField, strIDField, strTextField,
rst(strIDField)
     rst.Bookmark = bk     ' Return to last place and continue search.
     rst.FindNext strCriteria   ' Find next employee.
  Loop

exitAddBranch:
  Exit Sub

     '--------------------------Error Trapping
--------------------------
errAddBranch:
  MsgBox "Can't add child:  " & Err.DESCRIPTION, vbCritical,
"AddBranch Error:"
  Resume exitAddBranch
End Sub
Douglas J. Steele - 08 Nov 2006 19:05 GMT
Do you have a reference to Microsoft Windows Common Controls? (either
MSCOMCTL.OCX, or COMCTL32.OCX)

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Hi all,
>
[quoted text clipped - 79 lines]
>   Resume exitAddBranch
> End Sub
kerry_ja@yahoo.com - 08 Nov 2006 19:24 GMT
Hi Douglas,

I didn't.  I added the reference, and it works now.
Thanks

> Do you have a reference to Microsoft Windows Common Controls? (either
> MSCOMCTL.OCX, or COMCTL32.OCX)
[quoted text clipped - 87 lines]
> >   Resume exitAddBranch
> > End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.