I have a code with a recursive function that checks into a folder for folders and writes the name, ID, and depth of the folder in my database. The process is repeated until all folders are in the database (usually 200 folders per projects).
When I run the code with my code window open, I can see what the code is doing because of debug.print
, but since users never have the code window open, they can't see what's going on. I thought about 2 solutions.
I searched google but did not find a working solution to do the immediate window pop-up.
As for the second idea is there a way to just send the .print
to a textbox or is there something like a console object in vba?
I was using
Form_PrintWindow.PrintWindow.Text = xmlNode3.Attributes.getNamedItem("id").Text & " " & xmlNode3.Attributes.getNamedItem("name").Text & vbNewLine & Form_PrintWindow.PrintWindow.Text
But string gets full halfway in the process.
DebugOutput
and the listbox OutputList
)Add an UpdateProgress
sub to that form. It will add the output of your other process as new items to the listbox and select the most recently added item.
Public Sub UpdateProgress(text As String)
'add item and select it
With Me.OutputList
.AddItem text
.Selected(.ListCount - 1) = True 'zero based index
End With
DoEvents 'this frees up the OS to repaint the screen
End Sub
In your existing code, create a new instance of Form_DebugOutput
(or whatever you named your form. Note that access automatically prepends forms with Form_
.)
Instead of Debug.Print
call the UpdateProgress
method of the form instance we created.
Public Sub testit()
Dim output As New Form_DebugOutput
output.Visible = True
Dim i As Long
For i = 1 To 1000
output.UpdateProgress "I've said hello " & i & " times."
Next
Stop
End Sub
And it will look something like this.
Outputting the results in real time like this will slow the code down, so carefully consider if you really need to display this information. Also, if you want the form to remain on screen you will need to declare the Form
variable at a global scope. For more on this you may want to read about my progress bar.