MS Access VBA Create Instant Popup Or Simulate It

I have some code with a recursive function that checks a folder for folders and records the name, ID and depth of the folder in my database. The process is repeated until all folders are in the database (typically 200 folders per project).

When I run the open source code of my code, I can see what the code is doing from behind debug.print

, but since users never open the code window, they cannot see what is happening. I thought of two solutions.

  • Open "nearest window" as a popup on my form.
  • Create a form with a text box.

I searched google but couldn't find a working solution for the popup.

As for the second idea, is there a way to just send .print

to a textbox or is there something like a console object in vba?

I used

Form_PrintWindow.PrintWindow.Text = xmlNode3.Attributes.getNamedItem("id").Text & " " & xmlNode3.Attributes.getNamedItem("name").Text & vbNewLine & Form_PrintWindow.PrintWindow.Text

      

But the line fills up completely in the process.

+3


source to share


2 answers


  • Create a form with an empty list control of the appropriate size. (I named my form DebugOutput

    and list OutputList

    )
  • Add UpdateProgress

    to this form. It will add the output of your other process as new items to the list and select the last 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 Form_DebugOutput

    (or whatever you name your form. Note that access automatically adds forms with Form_

    .)

  • Instead, Debug.Print

    call the method UpdateProgress

    of the instantiated form.

    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.



form with process output

Outputting results in real time like this will slow down your code, so carefully consider whether you really need to display this information. Also, if you want the form to remain on the screen, you need to declare a variable Form

in the global scope. You can read more about this on my progress bar .

+1


source


My suggestion was to use SysCmd () to update the status bar.

The reason for this is that every time I tried to output to the form while the code was running, it hit and missed the one displayed to the user. I've never had a status problem.



 Function FolderImport()
 Dim statBAR as variant
 Dim fldName as string
 statBAR = SysCmd(acSysCmdInitMeter, "Processing Import of Folders", 200)
 For i = 1 to 200
    statBAR=SysCmd(acSysCmdUpdateMeter, i)
    DoCmd.RunSQL "INSERT INTO tblFOLDERS VALUES ('" & fldName & "');"
 Next i
 Forms.frm_NAV.lstFOLDERS.requery()
 End Function

      

This code is not 100% complete, but you get an idea of ​​what is going on. While the code is running, there is nothing the user can do, so displaying folders in the list box when running the code will be the same as running a query () after running the code. The status bar lets the user know that something is happening, so they don't think the program is frozen.

0


source







All Articles