I have 4 database's that I need to enter and run a macro in. The macro in each db is named the same. I am having difficulty creating a loop to go into one db run the macro exit and then go into another db run the macro exit, etc...
Any help appreciated
Function Delete()
Dim DbPath$
Dim intMacro As Integer
For intMacro = 0 To 4
Select Case intMacro
Case 0 'Delete Glenn
DbPath = "\\Stratford1\COMMON1\SHARED\DISPATCH\Overtime\Gle nn Laudenslager\OverTime(Glenn).mdb"
Dim db As New Access.Application
db.OpenCurrentDatabase (DbPath)
db.Visible = True
db.DoCmd.RunMacro ("DeleteInput")
db.Quit
Next intMacro
Case 1 'Delete Heather
DbPath = "\\Stratford1\COMMON1\SHARED\DISPATCH\Overtime\Hea ther Foster\OverTime(Heather).mdb"
db.OpenCurrentDatabase (DbPath)
db.Visible = True
db.DoCmd.RunMacro ("DeleteInput")
db.Quit
Next intMacro
7 1939
I have 4 database's that I need to enter and run a macro in. The macro in each db is named the same. I am having difficulty creating a loop to go into one db run the macro exit and then go into another db run the macro exit, etc...
Any help appreciated
Function Delete()
Dim DbPath$
Dim intMacro As Integer
For intMacro = 0 To 4
Select Case intMacro
Case 0 'Delete Glenn
DbPath = "\\Stratford1\COMMON1\SHARED\DISPATCH\Overtime\Gle nn Laudenslager\OverTime(Glenn).mdb"
Dim db As New Access.Application
db.OpenCurrentDatabase (DbPath)
db.Visible = True
db.DoCmd.RunMacro ("DeleteInput")
db.Quit
Next intMacro
Case 1 'Delete Heather
DbPath = "\\Stratford1\COMMON1\SHARED\DISPATCH\Overtime\Hea ther Foster\OverTime(Heather).mdb"
db.OpenCurrentDatabase (DbPath)
db.Visible = True
db.DoCmd.RunMacro ("DeleteInput")
db.Quit
Next intMacro
You have 4 Databases, but the For...Next is being executed 5 times. Change to:
You have 4 Databases, but the For...Next is being executed 5 times. Change to:
Good catch. Also make sure that when you change your loop from 1 to 4 (or 0 to 3) that you make sure to adjust your Select Case to match.
- Minion -
I have 4 database's that I need to enter and run a macro in. The macro in each db is named the same. I am having difficulty creating a loop to go into one db run the macro exit and then go into another db run the macro exit, etc...
Any help appreciated
Function Delete()
Dim DbPath$
Dim intMacro As Integer
For intMacro = 0 To 4
Select Case intMacro
Case 0 'Delete Glenn
DbPath = "\\Stratford1\COMMON1\SHARED\DISPATCH\Overtime\Gle nn Laudenslager\OverTime(Glenn).mdb"
Dim db As New Access.Application
db.OpenCurrentDatabase (DbPath)
db.Visible = True
db.DoCmd.RunMacro ("DeleteInput")
db.Quit
Next intMacro
Case 1 'Delete Heather
DbPath = "\\Stratford1\COMMON1\SHARED\DISPATCH\Overtime\Hea ther Foster\OverTime(Heather).mdb"
db.OpenCurrentDatabase (DbPath)
db.Visible = True
db.DoCmd.RunMacro ("DeleteInput")
db.Quit
Next intMacro
I made a couple of changes, try this code and see what happens: -
Function Delete()
-
Dim DbPath As String, db As Access.Application
-
Dim intMacro As Integer
-
-
For intMacro = 1 To 4
-
Select Case intMacro
-
Case 1 'Delete Glenn
-
DbPath = "\\Stratford1\COMMON1\SHARED\DISPATCH\Overtime\Glen n Laudenslager\OverTime(Glenn).mdb"
-
Set db = CreateObject("Access.Application")
-
db.OpenCurrentDatabase (DbPath)
-
db.Visible = True 'why?
-
db.DoCmd.RunMacro ("DeleteInput")
-
db.Quit
-
Case 2 'Delete Heather
-
DbPath = "\\Stratford1\COMMON1\SHARED\DISPATCH\Overtime\Heat her Foster\OverTime(Heather).mdb"
-
Set db = CreateObject("Access.Application")
-
db.OpenCurrentDatabase (DbPath)
-
db.Visible = True 'why?
-
db.DoCmd.RunMacro ("DeleteInput")
-
db.Quit
-
Case 3 'additional code needed here
-
Case 4 'additional code needed here
-
Case Else
-
'drop thru code, won't happen, but
-
Next intMacro
-
End Function
If you're doing what I think your are doing it occurs to me that you have a consistency of folder path and a naming convention for your mdb files that basically provides one overtime mdb per person.
Have a look at this merely as 'food for thought' in that if you get any more people added to the overtime path folder having their own mdb file then simply adding their name to the array and resizing it will provide for examining future mdb files and running the macro in each one of their mdb files as well.
You can enhance this routine of course , but no point unless you have a variable number of people etc etc...error handling needs addressing too. -
-
Function fn_DeleteInputs()
-
Dim db As New Access.Application
-
Dim sharedpath As String, filename As String
-
Dim strperson(1) As String
-
'define the various elements of the zero based array
-
strperson(0) = "Glenn Laudenslager"
-
strperson(1) = "Heather Foster"
-
'if and only if the folder location is fixed and the mdb file naming convention is consistent
-
'then define a path commensurate with the person name and pin the name of the
-
'mdb to it BUT ONLY if we can parse first name from surname and concatenate the file extension
-
'Loop through the elements of the array during 'one' instance of the Access
-
'application (resource preservation)and run the macro in each database.
-
'Close off and quit after loop finishes
-
For Each element In strperson
-
sharedpath = "\\Stratford1\Common1\Shared\Dispatch\Overtime\" & element & "\"
-
filename = "Overtime(" & Trim(left(element, InStr(element, " "))) & ").mdb"
-
Debug.Print sharedpath & filename
-
db.OpenCurrentDatabase (sharedpath & filename)
-
db.DoCmd.RunMacro ("DeleteInput")
-
db.CloseCurrentDatabase
-
Next
-
db.Quit
-
End Function
-
Regards
Jim :)
If you're doing what I think your are doing it occurs to me that you have a consistency of folder path and a naming convention for your mdb files that basically provides one overtime mdb per person.
Have a look at this merely as 'food for thought' in that if you get any more people added to the overtime path folder having their own mdb file then simply adding their name to the array and resizing it will provide for examining future mdb files and running the macro in each one of their mdb files as well.
You can enhance this routine of course , but no point unless you have a variable number of people etc etc...error handling needs addressing too. -
-
Function fn_DeleteInputs()
-
Dim db As New Access.Application
-
Dim sharedpath As String, filename As String
-
Dim strperson(1) As String
-
'define the various elements of the zero based array
-
strperson(0) = "Glenn Laudenslager"
-
strperson(1) = "Heather Foster"
-
'if and only if the folder location is fixed and the mdb file naming convention is consistent
-
'then define a path commensurate with the person name and pin the name of the
-
'mdb to it BUT ONLY if we can parse first name from surname and concatenate the file extension
-
'Loop through the elements of the array during 'one' instance of the Access
-
'application (resource preservation)and run the macro in each database.
-
'Close off and quit after loop finishes
-
For Each element In strperson
-
sharedpath = "\\Stratford1\Common1\Shared\Dispatch\Overtime\" & element & "\"
-
filename = "Overtime(" & Trim(left(element, InStr(element, " "))) & ").mdb"
-
Debug.Print sharedpath & filename
-
db.OpenCurrentDatabase (sharedpath & filename)
-
db.DoCmd.RunMacro ("DeleteInput")
-
db.CloseCurrentDatabase
-
Next
-
db.Quit
-
End Function
-
Regards
Jim :)
Nice catch, Jim, and more efficient too. Well, another one that went right over-my-head! (LOL).
Thanks for the advise, will try and see how it goes!
Nice catch, Jim, and more efficient too. Well, another one that went right over-my-head! (LOL).
Thanks so much! The loop ran perfectly!
Nice catch, Jim, and more efficient too. Well, another one that went right over-my-head! (LOL).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ArShAm |
last post by:
Hi there
Please help me to optimize this code for speed
I added /O2 to compiler settings
I added /Oe to compiler settings for accepting register type request , but
it seems that is not allowed...
|
by: Dom Boyce |
last post by:
Hi
First up, I am using MS Access 2002.
I have a database which records analyst rating changes for a list of
companies on a daily basis. Unfortunately, the database has been set
up (by my...
|
by: Sarah |
last post by:
Hi,
I have an Access database of about 1000 records. I am trying to use
asp to loop through the record set one at a time, creating the html
code for a web page. I would like to save the actual...
|
by: steven |
last post by:
I am creating some financial reports in Access 2000, and I am having
problem that I can't resolve.
The report sorts information first by vendor, then by budget line
number. It generates the...
|
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application...
|
by: Tarun Mistry |
last post by:
Hi all, I have posted this in both the c# and asp.net groups as it applies
to both (apologies if it breaks some group rules).
I am making a web app in asp.net using c#. This is the first fully OO...
|
by: mslyman |
last post by:
Hi,
I could do with some help. I have this XML.
<region>
<region_code>567</region_code>
<store>
<store_code>345</store_code>
<dept>
<dept_code>32</dept_code>
</dept>
|
by: kberry |
last post by:
I am clearing Textboxes on a form... this is loop I have came up with
but was wondering if it can be shorter or not as long... Can anyone
help?
Dim controlOnForm As Control 'Places a control...
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted...
|
by: bcap |
last post by:
Hello,
I really would apprciate help! =)
What I want to do is be able to change the status of mulitple records
using a drop down and a checkbox.
I have a drop down called "ChangeStatus"...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
| |