Compile Error but not understanding why this has happened....

Hi all,

I am trying to call some macros in Access 2010 using a loop, but get an error message before I can even step into it.

I could manually run all of the macros, but this seems tedious and I can't figure out why this isn't working!

I have macros names UpdateTableProcess5_ACD, UpdateTableProcess6_ACD, UpdateTableProcess7_ACD etc. up to UpdateTableProcess44_ACD.

I have written the following code, but this generates the following error...

Compile Error: Expected Sub, Function or Property

Sub CallAll()

Dim strMacro As String
Dim i As Integer


For i = 5 To 44

    strMacro = "UpdateTblProcess" & i & "_ACD"

    Call strMacro

Next i



End Sub

Open in new window



Does anyone have any ideas how to work around this?

Thanks,

Sarith
Sarith GadaData AnalystAsked:
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.

NorieAnalyst Assistant Commented:
Sarith

You can't call macros like that in Access, try this.
Sub CallAll()

Dim strMacro As String
Dim i As Integer


For i = 5 To 44

    strMacro = "UpdateTblProcess" & i & "_ACD"

    DoCmd.RunMacro strMacro

Next i



End Sub

Open in new window

1
Sarith GadaData AnalystAuthor Commented:
Hello,

Thank you for your response.

I now have an error message: Run-time error '2485' with message : Microsoft Access cannot find the object 'UpdateTblProcess5_ACD.'
0
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
You should use
Application.run strMacro

Open in new window

for code procedures. RunMacro is only for stored macros (The ones created through the GUI).
1

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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

NorieAnalyst Assistant Commented:
Anders

I was assuming Sarith was referring to stored macros.:)
2
Sarith GadaData AnalystAuthor Commented:
Thank you! Worked perfectly well!
0
Gustav BrockCIOCommented:
Try with:

strMacro = "UpdateTblProcess" & i & "_ACD()"
Eval(strMacro)

Open in new window

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.