run onclick event of access db A from db B

I have a sub in a db that I want to run from another db how do i do that?

am in access 2010
PeterBaileyUkAsked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You'd have to automate dbB from dbA:

Dim objAccess As Object
Dim frm As Object

Set objAccess = CreateObject("Access.Application")
obAccess.OpenCurrentDatabase "Full path to dbB"
objAccess.DoCmd.OpenForm "YourForm"
Set frm = objAccess.Forms("YourForm")

Call frm.YourButton_Click()

However, if you need to call code from more than one place, you really should move it to a Sub or Function and call it as needed.
0
 
PeterBaileyUkAuthor Commented:
getting run time error 2465 application-defined or object defined error


Dim objAccess As Object
Dim frm As Object

Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase "d:\data\smmt\smmt_comparitor.mdb"
objAccess.DoCmd.OpenForm "FrmMenu"
Set frm = objAccess.Forms("FrmMenu")

Call frm.BtnCalculateDifferencesandAppendToTables_Click ...fails here
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Can you determine if the "frm" variable has actually be set to the correct form reference?

Did you include the parentheses at the end of the Click event? Not exactly sure about the syntax, as I've never had need to work with Access forms in this manner.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
PeterBaileyUkAuthor Commented:
adding a watch to the object shows 3 items and the form has three buttoms but whether that is enough I am not sure never did this before.

in answer to your second question

Call frm.BtnCalculateDifferencesandAppendToTables_Click

wont allow inclusion of ()
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Note that the Sub/Function must be marked as PUBLIC in order for this to function:

Sub_YourSubName()

should instead be

Public Sub_YourSubName()



0
 
PeterBaileyUkAuthor Commented:
thank you was the public sub holding it back
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.