ow to print a tree view (1 Viewer)

Arcadium

New member
Local time
Today, 17:35
Joined
Nov 17, 2025
Messages
2
Ignorant newbie here needing help with calling a function. I'm trying to print an expanded tree view screen but keep getting various errors depending upon the structure of the call statement. Always fails on the "GetTreeViewText() line in the Sub. The latest version is as below. The form named "frm_treeview", the tree view object in the form is named "TreeReqs".What should be the correct syntax?

Private Sub PrntForm_Click()
GetTreeViewText (Me.Controls("TreeReqs")). <-- fails on this line
end subb

'GetTreeViewText (Forms("frm_Treeview").Controls("TreeReqs").Form) <-- another variation also fails


Function GetTreeViewText(treeView As treeView) As String
Dim treeText As String
Dim node As node
..
..
..
end function
 
Not sure what you are trying to do when you say "print an expanded tree view screen". Print what how - content of nodes to printer paper or PDF?

Not first time this has been asked https://www.access-programmers.co.uk/forums/threads/print-treeview-control.61400/

My Bing search returned AI response that basically paraphrases that thread.

If you want to provide db for analysis, follow instructions at bottom of my post.
 
Last edited:
No a lot there, is there? :(
You do not show the code in that function?
You also do not say what error(s) you get?

Help us to help you.
I know nothing about Treeviews. @MajP appears to be a treeview expert.

Hopefully he will chip in.

I am suprised that treeView is not TreeView, if it was recognised as an object?
 
maybe change the function to:
Code:
Function GetTreeViewText(tv As Object) As String
Dim treeText As String
Dim node As node
..
..
..
end function
 
Me.Controls("TreeReqs") is an Access.CustomControl object that only hosts the Treeview. Use its .Object property to expose the Treeview inside it, like...
Code:
Private Sub PrntForm_Click()
    GetTreeViewText Me.TreeReqs.Object
End Sub
 
A treeview is an ActiveX control in the MSCOMCTL library.
MSCOMCTL.OCX refers to the Microsoft Windows Common Controls ActiveX library, a legacy component that provides UI elements like:
• ListView
• TreeView
• ImageList
• ProgressBar
• TabStrip
• Toolbar
• StatusBar
These controls were widely used in Visual Basic 6.0 and VBA environments

Similar to when we call the subform control and the form inside the subform control a "sub form". Even though two different things. There is the treeview activeX control of class (Access.CustomControl) and then the treeview object inside the active x control of class (TreeView).

However, it also looks to me that the print function returns a string of values so the code is probably something like this

Code:
Private Sub PrntForm_Click()
  Dim strOut as string
  StrOut = GetTreeViewText (Me.TreeReqs.object)
  me.txtBoxOut = strOut
end sub

Function GetTreeViewText(tvw As treeView) As String
  Dim treeText As String
  Dim nd As node
  for each Nd in tvw.nodes
    TreeText = treeText & vbcrlf & nd.text
  next nd
  GetTreeViewText = treeText
end function
 
Last edited:
acCustomControl is a generic term that refers to all ActiveX controls such as Treeview

1763560259231.png
 
Thank you to all that replied and helped me. I didn't understand the .object nuance. I implemented the MajP changes and now get a print-out of the tree view object. Special thanks to MajP and isladogs.
 
I tested the code and it does output a string of node contents (I passed string to MsgBox).

So what do you mean by "print". Nothing in the given code actually prints anything, just saves a string to a textbox.

I also tested OutputTo method to create a PDF of the form. That works as well. Reproduces the graphical presentation of TreeView control.
 
i also tested my code before posting and it does work, just for clarification.
 

Users who are viewing this thread

Back
Top Bottom