Open another database and send Variable Back

johnnyc

Registered User.
Local time
Yesterday, 20:47
Joined
Sep 23, 2014
Messages
26
I have code that from DB1 opens DB2 and runs a Function in DB2.

The DB2 function produces a Boolean result that i am trying to get back to DB1 without success. Any suggestions? below is the script.

Sub Test22()
Dim AC As Object
Set AC = CreateObject("Access.Application")

rc = "K:\ARSHR\Automation_Projects\Mike\FE\DB2.accdb"
AC.OpenCurrentDatabase (rc)
AC.Visible = True
AC.Run "SendVariable"

End Sub

Because i am using AC.Run "SendVariable" i cant find a way to get the value of SendVariable!!
 
I haven't done this myself but I think the way to go about it would be to create custom property of the DB you are opening. Set the custom property to true or false whatever you need, once your code has run then access that custom property from your calling database.

Like I said I haven't done this and before you go to a lot of trouble I suggest you check the following things out. If this method is to work you will need to be able to create a custom property for a database I'm ninety-nine percent sure that this is possible.

The next issue is, can you access a database custom property from VBA code? I don't know the answer to that, I assume you can but I would check out that assumption with some simple checks first, or find some indication that someone else has already done this before you waste too much time on this method.
 
I just ran code like this . . .
Code:
Sub Test22()
    With CreateObject("Access.Application")
        .OpenCurrentDatabase "c:\yourDatabase.accdb"
        Debug.Print .Run("SomeFunction", "1234")
        .Quit
    End With
End Sub
. . . and it works fine. "Run" executes a Sub OR a Function, so if your routine returns a value, then you can assign it to a variable. In the code I posted, I just print it to the immediate pane, but it returns a value just fine.
 

Users who are viewing this thread

Back
Top Bottom