Ian Cox
Ian Cox

Reputation: 95

send debug.print to different Immediate window

I have set up a multithreading routine in Access which opens up several Access files at the same time and executes a specific function in each file. The files act in parallel. I would like to send Debug.Print messages to the main file which initiates the multithreading.

I'm not sure if it can do this or if there is a better solution.

Upvotes: 1

Views: 539

Answers (2)

Mathieu Guindon
Mathieu Guindon

Reputation: 71217

You have a number of processes, each working on their own part of the bigger picture.

The immediate pane of the "main" IDE belongs to that instance, in that process; you could Alt+Tab and then Alt+F11 to bring up a VBE instance in any/every instance to view that instance's Debug.Print output.

What you want is something like an ILogger implementation that writes the log entries in a dedicated database table: a DatabaseLogger, for example.

You replace Debug.Print with Logger.Log calls; that way you let the database server deal with the multiple incoming threads, and depending on the RDBMS you could even setup a job to cleanup, aggregate and/or archive the older log records. Or whatever, as long as it's not logic I need to care about in VBA code.

Writing to another VBE's immediate toolwindow involves low-level, cross-process Win32 wizardry that doesn't need to clutter up an otherwise nice & tidy VBA project. I wouldn't bother with that, there are simpler solutions.

Upvotes: 1

ThunderFrame
ThunderFrame

Reputation: 9461

You could create a PublicNotCreatable UserForm (not an Access Form) in the main application, and pass a reference to it, to all of the parallel apps. Add a custom method to the UserForm, like 'PrintLine(message as string), and each app can callform.PrintLine("app is running")`?

You could then have the UserForm display the output, or possibly, have the UserForm output the message to the Immediate window of the main application.

Upvotes: 0

Related Questions