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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.