472,809 Members | 4,824 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,809 software developers and data experts.

Call Macro from closed Data Base

5
Greetings,

I have been searching the web and Access relentlessly trying to find a way to call an Access macro from a different Access data base.

Example - The form button gets clicked and the first macro executes. Then a second macro is selected from a closed data base so that the query in the second database can run. Alternatively open the second data base and call the macro.

In other words I need to use several Access databases and want the one with the form to control the others via the onclick command macro.
Apr 4 '07 #1
4 13058
MMcCarthy
14,534 Expert Mod 8TB
Greetings,

I have been searching the web and Access relentlessly trying to find a way to call an Access macro from a different Access data base.

Example - The form button gets clicked and the first macro executes. Then a second macro is selected from a closed data base so that the query in the second database can run. Alternatively open the second data base and call the macro.

In other words I need to use several Access databases and want the one with the form to control the others via the onclick command macro.
Fistly, you can't just call a macro from another database. The best you could hope for is to do some pretty complicated VBA code to open the other database and preform actions duplicating what is currently being done by the macro.

Mary
Apr 4 '07 #2
ADezii
8,834 Expert 8TB
Greetings,

I have been searching the web and Access relentlessly trying to find a way to call an Access macro from a different Access data base.

Example - The form button gets clicked and the first macro executes. Then a second macro is selected from a closed data base so that the query in the second database can run. Alternatively open the second data base and call the macro.

In other words I need to use several Access databases and want the one with the form to control the others via the onclick command macro.
What you are referring to is Automation Code utilizing Access as an Automation Server.

The following code will run Macro1 in the C:\Test\Test.mdb Database from the current Access Database. As far as I known, Automation is the only way to effectively control Objects in External Access Databases from a Current Access Database. Here are the steps which must be followed in strict sequence.

__1. In a Form's Declarations Section, declare a variable as Access.Application. This variable will soon be a legitimate reference to an external Access Application.
Expand|Select|Wrap|Line Numbers
  1. Dim objAccess As Access.Application
__2. Place the following code which will create a New Instance of Access and run the Macro in an appropriate Event Procedure.
Expand|Select|Wrap|Line Numbers
  1. Set objAccess = CreateObject("Access.Application")
  2.  
  3. objAccess.Visible = True
  4.  
  5. 'Open Test.mdb exclusively
  6. objAccess.OpenCurrentDatabase "C:\Test\Test.mdb", True
  7.  
  8. 'Execute Macro1 which will open qryEmployees Maximized on screen
  9. objAccess.DoCmd.RunMacro "Macro1"
  10. objAccess.DoCmd.Maximize
__3. Destroy the previously created Instance of Access when you are finished with it.
Expand|Select|Wrap|Line Numbers
  1. Set objAccess = Nothing
Apr 4 '07 #3
AI Man
5
This is a listing of some of my coding. Hope it helps people.

'Create a second Access session
Public Sub OpenAccess()
Dim appAccess As New Access.Application
Set appAccess = Access.Application
appAccess.OpenCurrentDatabase "\\Foldername\Databasename.mdb"

appAccess.DoCmd.RunMacro "Macro Name", , ""
' Can't remember exact wording for the above line of code. I think whats shown is correct. Might be a straight DoComd.RunMacro

appAccess.Visible = True
End Sub



To run Excel Macro's
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add("\\Folder name\Report name.xls")
xlApp.Visible = False
xlApp.Application.Run "Name of macro"
xlApp.activeworkbook.Close
Set xlApp = Nothing
Set xlBook = Nothing



To email MULTIPULE documents from Access.
***Must save file first and then attach it to an email.***

Dim olapp As Object
Dim olns As Object
Dim olfolder As Object
Dim olitem As Object
Dim olattach As Object

Set olapp = CreateObject("Outlook.Application")
Set olns = olapp.GetNamespace("MAPI")
Set olfolder = olns.getdefaultfolder(6)
Set olitem = olapp.createitem(0)
Set olattach = olitem.attachments

olitem.To = "Fred Flintstone"
olitem.CC = "Mr. Slate"
olitem.Subject = "Quarry Productivity"
olitem.body = "Please find enclosed the weekly Productivity Reports" & Chr(13) & Chr(10)

olattach.Add "PathTo1stFile", 1
olattach.Add "PathTo2ndFile", 1
olattach.Add "pathTo3rdFile", 1

olitem.display
olitem.send

Set olitem = Nothing
Set rs = Nothing
Set db = Nothing
Set olfolder = Nothing
Set olns = Nothing
Set olapp = Nothing
Apr 9 '07 #4
AI Man
5
The last post has some minor items to clarify. Here is the same data with more clarification. Specifically clarifing how to use the path ways.

'Create a second Access session
Public Sub OpenAccess()
Dim appAccess As New Access.Application
Set appAccess = Access.Application
appAccess.OpenCurrentDatabase "\\Path to folder holding Database\Database name.mdb"

appAccess.DoCmd.RunMacro "Macro Name", , ""
' Can't remember exact wording for the above line of code. I think whats shown is correct. Might be a straight DoComd.RunMacro

appAccess.Visible = True
End Sub



To run Excel Macro's
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add("\\Path to folder holding workbook\workbook name.xls")
xlApp.Visible = False
xlApp.Application.Run "Name of macro"
xlApp.activeworkbook.Save
xlApp.activeworkbook.Close
Set xlApp = Nothing
Set xlBook = Nothing



To email MULTIPULE documents from Access.
***Must save file first.***

Dim olapp As Object
Dim olns As Object
Dim olfolder As Object
Dim olitem As Object
Dim olattach As Object

Set olapp = CreateObject("Outlook.Application")
Set olns = olapp.GetNamespace("MAPI")
Set olfolder = olns.getdefaultfolder(6)
Set olitem = olapp.createitem(0)
Set olattach = olitem.attachments

olitem.To = "Fred Flintstone"
olitem.CC = "Mr. Slate"
olitem.Subject = "Quarry Productivity"
olitem.body = "Please find enclosed the weekly Productivity Reports" & Chr(13) & Chr(10)

olattach.Add "PathTo1stFile", 1
olattach.Add "PathTo2ndFile", 1
olattach.Add "pathTo3rdFile", 1

olitem.display
olitem.send

Set olitem = Nothing
Set rs = Nothing
Set db = Nothing
Set olfolder = Nothing
Set olns = Nothing
Set olapp = Nothing
Apr 9 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: MHenry | last post by:
Hi, I know virtually nothing about creating Macros in Access. I would appreciate some help in creating a Macro or Macros that automatically run(s) 14 Queries (three Make Table Queries, and 11...
27
by: Ken Human | last post by:
I want to generate every possible 16 character combination of the characters 0-9, A-Z, and a-z programatically. My current code follows: #include <stdio.h> #include <ctype.h> int main() {...
0
by: Mythran | last post by:
I have a class which inherits Form and would like it to display modally from a macro. I want it to stay in front of the .Net IDE until the user presses Ok and would like the IDE to be locked from...
28
by: Jack Morgan | last post by:
I got a macro like this in my code. > #define DECLARE_SOMEWNDSTRUCTURE(style, nums, clrref, icon, tablenum, name, menuname)\ static SOMEWNDSTRUCT &GetSomeWndStruct()\ {\ static SOMEWNDSTRUCT...
12
by: Tom | last post by:
I use dynamically created controls all the time. I.E. I create the control in code then use AddHandler to add the necessary delegates for processing (like Click, etc). Does one have to call...
5
by: Frederick Gotham | last post by:
If we have a simple class such as follows: #include <string> struct MyStruct { std::string member; MyStruct(unsigned const i) {
8
by: Pawel | last post by:
Hallo group members. //p1.cpp #include <stdio.h> #include <linux/stddef.h> struct Person { int m_age; char* m_name; };
6
by: Doug Ferguson | last post by:
I am using a webservice client that was created from a WSDL file in .Net 1.1. The client ALWAYS works the first time I call it. The second call returns one of two exceptions. It either returns...
1
by: slickdock | last post by:
My vb code saves a record as a Word merge data file and merges it with a Word merge form file. Once the merge is complete, I would like the code to make this determination: There will always be...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.