Solved

How do I execute a module in Access 2007

Posted on 2009-05-06
9
1,876 Views
Last Modified: 2012-06-27
I used to quite like the previous "macro" functionality

However if I have the attached script in Access 2007 how do I execute it without going to the code and clicking "Run"



Function Rebuild()

On Error GoTo Proc_030_Err
 

DoCmd.SetWarnings False
 

    DoCmd.OpenQuery "100 Clear Temp 01 ARSHIP with keys", acViewNormal, acEdit

    DoCmd.OpenQuery "110 ARSHIP with keys", acViewNormal, acEdit

    DoCmd.OpenQuery "300 Clear Temp 03 Sales F2007 on", acViewNormal, acEdit

    DoCmd.OpenQuery "310 Rebuild Temp 03 Sales F2007 on", acViewNormal, acEdit
 

    MsgBox "Tables Rebuilt", vbInformation, "Finished"

    

DoCmd.SetWarnings True
 

Proc_030_Exit:

    Exit Function
 

Proc_030_Err:

    MsgBox Error$

    Resume Proc_030_Exit
 

End Function

Open in new window

0
Comment
Question by:Zarbs
  • 4
  • 4
9 Comments
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
in the immediate window:
x = Rebuild()
0
 

Author Comment

by:Zarbs
Comment Utility
Sorry ... .I don't understand what you mean
0
 
LVL 30

Accepted Solution

by:
hnasr earned 250 total points
Comment Utility
You have a function called Rebuild() in a module
Open the module and a window called immediate shows at the bottom.
If not shown select view menu > Immediate Window
In the immediate window type:
x = Rebuild() to run that function

You can use it through code depending on your project.
0
 

Author Comment

by:Zarbs
Comment Utility
Thanks - I'll give it a go tomorrow when I get to work

Cheers
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
Comment Utility
Or add a button to a Form, the use the Click event of that button to run your code:

Sub MyButton_Click()
  Rebuild
End Sub

Or add a Macro with the RunCode action, with the argument set to "Rebuild()"
0
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
Real expert's comment should be:
As hnasr suggested "You can use it through code depending on your project." , add.... or ....
;-)
0
 

Author Comment

by:Zarbs
Comment Utility
I must have missed something.

LSMConsulting - I don't really want to have a form .... I just wish to click the object in the modules section and have the code execute.   This is what I would have done in access 2003 and earlier when a macro would run

hnasr - what you suggested did not seem to work.  See atached screen as to what I did
8-05-2009-8-31-34-a.m..jpg
0
 

Author Comment

by:Zarbs
Comment Utility
I really did miss something in that I discovered you can still create macros in Access 2007 .... which allowed me to run my code as I wanted by running that piece of code

Thanks to you both
0
 
LVL 30

Expert Comment

by:hnasr
Comment Utility
" I just wish to click the object in the modules section and have the code execute."

Click at End Function line
Press Ctrl+F8
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now