I an new to MS access and I took over someone's role where it involves running almost 20 MS access databases everyday taking me close to 2 hours . I really wanna automate it.
1. I open each MS access database file and then run a macro in it and close file . There are several macros in each file and lot of tables but everyday i just run one in each.
2. Repeat same step for other 20 MS access files
How can i automate it so that each access file opens by itself > execute the specified macro > close > move to other file
13 14550 zmbd 5,501
Expert Mod 4TB
Hello Hansy,
Would you take a moment to clarify something for me:
Do you mean Access-Macros Or do you mean Access-VBA
These are very different beasties and call/implementing them are quite different.
The confusion comes from MSExcel calling VBA-Scripts "Macros;" however, MSAccess has two distinct programing environments, Macros and VBA scripts.
... another question comes to mind
What do these 20 different databases do and are they related?
zmbd 5,501
Expert Mod 4TB @NeoPaInvoking a Database From the Command Line should hopefully give you all you need to look into this
Hopefully this works for Hansy; however, if Hansey is dealing with a highly locked down PC the command line scripts and access to the scheduler are locked out by GPO-Sec.
I've had to find workarounds for all of my dot-BAT, dot-PS1 files, and all of my scheduled runs were removed by GPO and IT-Security refuses to allow an exception - drives me bonkers!
NeoPa 32,556
Expert Mod 16PB
Hi Z.
That sucks. I've never worked anywhere where even CMD files are locked down.
Not that the basic concept relies on the CMD file though, as you can run the same script (series of commands to invoke Access in this case) from another database if you wanted to.
First and foremost, I'd like to say hi to two of my favorite people in the Access world, namely NeoPa and zmbd. I hope that both of you are doing well. I came up with, what I thought, could be a possible solution to your problem in a record amount of time, so please keep in mind that there is probably much room for improvement. The above being said, I assumed that you meant literal Access Macros, but it really doesn't make a difference since the Logic would pretty much be the same in either case. In any event, here it goes: - I created a Table named tblDBToRunMacros that consisted of only 2 Fields, namely: [ID]{AUTO -PK} and [DB_Path]{TEXT}.
- [DB_Path] contains the Absolute Path to your 20 or more External DBs.
- I created a Sub-Routine named RunMacro() that accepts a single Macro Name to Execute in each of the DBs.
- This Sub-Routine is called and an Argument is passed to it, in this case mcrDemo.
- In RunMacro(), each DB in tblDBToRunMacros is opened as the Current Database and a Macro (mcrDemo) is Executed.
- The above generalities aside, I tested this approach on multiple Northwind Databases and it actually worked quite well. The same Macro (mcrDemo) was Executed in each DB.
- I posted the relevant Code along with the actual Call below. Needless to say, there are many things that can still go wrong in actual execution.
-
Public Sub RunMacro(strMacroName As String)
-
Dim MyDB As DAO.Database
-
Dim rstDBs As DAO.Recordset
-
Dim appAccess As Access.Application
-
-
Set MyDB = CurrentDb
-
Set rstDBs = MyDB.OpenRecordset("tblDBsToRunMacros", dbOpenForwardOnly)
-
-
With rstDBs
-
Do While Not .EOF
-
Set appAccess = New Access.Application
-
-
With appAccess
-
'Open External DB in Microsoft Access Window.
-
.OpenCurrentDatabase rstDBs![DB_Path]
-
-
.DoCmd.RunMacro strMacroName 'Run the Macro
-
.CloseCurrentDatabase 'Close the DB
-
.Quit
-
End With
-
-
Set appAccess = Nothing
-
.MoveNext
-
Loop
-
End With
-
-
rstDBs.Close
-
Set rstDBs = Nothing
-
End Sub
-
@zmbd They seem as macros to me ( do not see any vba scripting) . The macros in each of the files read input from a specific file in our ftp location and update each tab in our excel (access excel file). I am sorry if i cant explain it well cos I have no idea on it , I just run each macro in these files and it updates our excel with the data we want. Process works wonderfully but is time taking and manual.
@adezii Hello , thankyou ..I could try this out but where would I define this code ? and do macros that i need to run in each of the separate access database be renamed as same name in all ?
..I could try this out but where would I define this code
One possibility would be in the Click() Event of a Command Button. do macros that i need to run in each of the separate access database be renamed as same name in all ?
Not at all. You could add the Macro Name along with Database Name in tblDBsToRunMacros. You would then need to pass another Argument (strMacroName As String) to the RunMacr() Sub-Routine and process accordingly.
zmbd 5,501
Expert Mod 4TB @ADeziiThe above being said, I assumed that you meant literal Access Macros, but it really doesn't make a difference since the Logic would pretty much be the same in either case. In any event, here it goes:
🙋 Hello There yourself...
👍👍👊 I'm going to steal the table idea - I haven't tested this; however, nicely done. I have several DB that I've simply hard-coded into the VBA that run to update the databases; however, in my case I'm importing CSV files that we receive from various instruments into the database. I used to do some of this with batch/PowerShell files and the scheduler before IT locked everything down! @hansyThey seem as macros to me ( do not see any vba scripting)
🐧Curious about why one is pulling the data to Excel. If this is for data manipulation the Excel workbooks can be linked to the Access data tables - this should eliminate the need to run each of the DBs. You might want to start a new thread if you're interested in doing this... we'd need a lot more information.
🐧Realized a picture saves a thousand words... if you're running under the [Macros] tab, then, you're not running a VBA script. NeoPa 32,556
Expert Mod 16PB
Hi guys.
Just a quick "Hello" for my old friend ADezii (and one for my much newer friend zmbd too of course). Both extremely competent Access experts in their own rights.
@hansy:
Regarding your mentioning of various Macro Names for each DB, you can simply add a [MacroName] Field to tblDBsToRunMacros and reference it within the Recordset Loop. There is also the added benefit of not passing a Macro Name to the RunMacro() Procedure. -
Public Sub RunMacro()
-
Dim MyDB As DAO.Database
-
Dim rstDBs As DAO.Recordset
-
Dim appAccess As Access.Application
-
-
Set MyDB = CurrentDb
-
Set rstDBs = MyDB.OpenRecordset("tblDBsToRunMacros", dbOpenForwardOnly)
-
-
With rstDBs
-
Do While Not .EOF
-
Set appAccess = New Access.Application
-
-
With appAccess
-
'Open External DB in Microsoft Access Window.
-
.OpenCurrentDatabase rstDBs![DB_Path]
-
-
.DoCmd.RunMacro rstDBs![MacroName] 'Run the Macro for the DB
-
.CloseCurrentDatabase 'Close the DB
-
.Quit
-
End With
-
-
Set appAccess = Nothing
-
.MoveNext
-
Loop
-
End With
-
-
rstDBs.Close
-
Set rstDBs = Nothing
-
End Sub
-
NOTE: A typical tblDBsToRunMacros would now look like:
Just a thought.
Why not use code to start each of the databases in turn using the /x command line switch ro run a specified macro
For example: - "G:\MyFiles\ExampleDatabases\TestDB\TestDB.accdb" /x "mcrExportDataToExcel"
Thankyou everyone for your suggestions. I am going to try them and see what works in my situation since I am a newbie to Access so it will take bit of time for me to implement them.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: MHenry |
last post by:
Hi,
We were going merrily along for 6 years using this database to record
all client checks that came into our office, including information
about what the checks were for.
Suddenly, network...
|
by: ronwer |
last post by:
Hello,
The title doesn't completely cover the question I have, but it's a bit more
complicated problem we have.
We are using a database, based on Acces, but developed by a third party...
|
by: mikemalin |
last post by:
I've done some research on the net and think I have an answer, but I'm
just looking for some other opinions.
I would like to create an access database file to distribute to others.
I would use...
|
by: James |
last post by:
Dear Access Guru's,
Hopefully you can help me (as Microsoft don't seem to be able to)
We have an Access database on a Windows 2003 server with 5 CALS in our
office.
Access is loaded onto...
|
by: rosli bakar |
last post by:
I'm quite new to VB and need help urgently . I have 2 Access database files
which need to connected/join to each other.
Database file 1 is in c:\dha\ABC.mdb
table: LogAlarm
Work Week | Alarm...
|
by: farseer |
last post by:
Hi,
i would like to write an app that will do the following:
1. download a csv file from an http url. fields are delimited by the
"|"
2. i would like to import this into an access database...
|
by: MadCrazyNewbie |
last post by:
Hey Group,
Wonder if somebody could help me please?
Im after a way in either Access or SQL to be able to store .xls, .doc, .pdf
& a few other files?
Is this possible, anybody got any links...
|
by: willington79 |
last post by:
Hello all,
We have a payroll application that runs with MS Access. It is comprised
of several different database files and one ms access mdb file for each
client. This means there can be from...
|
by: dave |
last post by:
Hello:
In Visual Studio 6.0 there is "VisData"
to create Access database files. (file.MDB".
Q:
Does Visual Studio 2005 have tool(s)
that create Access database files (file.MDB) ?
thank...
|
by: Richard Finnigan |
last post by:
Hi
I'm having real difficulties getting a very simple access database file to
show its data in visual studio data controls with various error messages
occuring. I've changed the permissions on...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |