Question

I am looking for a solution to effectively communicate between two running MS Access applications.

The approaches I tried so far is to use a common linked table and to use MSMQ service for communication. Both approaches work, but there is no way to "push" the data or command from one application to another and since MS Access doesn't support multi-threaded execution of VBA code, it is very difficult to implement polling without performance disadvantages.

Same time, VBA does support the addressof operator (from version 2000) that means we can also theoretically implement call-back functions in VBA and MS Access. But I have never seen any example how this can be used for inter-process communication and would appreciate any minimal example how I can send a string from one MS Access application to another without monitoring a shared table all the time.

Was it helpful?

Solution

You can use GetObject() to return the Access.Application object from another running db. With the application object you have access to just about everything you might need. Here's a contrived example of opening a form (but you can do a myriad of other things with the Application object):

Sub TestInterop()
Const mdbPath As String = "C:\OtherApp.mdb"
Dim OtherApp As Access.Application

    Set OtherApp = GetObject(mdbPath)
    OtherApp.Visible = True
    OtherApp.DoCmd.OpenForm "Accounts"
End Sub

If the program is not already running, the GetObject() call will start the application (you would need to be careful if you have multiple versions of Access installed as it's difficult to know at runtime which version would actually open the .mdb). However, if GetObject() needs to start the app, it will do so with the visibility set to False, so we explicitly set it to True. If the app is already running, setting its Visibility to True will have no effect.

OTHER TIPS

Consider it a wild idea, but may be put all your tables into sql express and/or sql ce and make look like a frontend to those tables?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top