Solved

How do I execute a module in Access 2007

Posted on 2009-05-06
9
1,881 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
ID: 24322307
in the immediate window:
x = Rebuild()
0
 

Author Comment

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

Accepted Solution

by:
hnasr earned 250 total points
ID: 24323180
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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

Author Comment

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

Cheers
0
 
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 24323571
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
ID: 24326593
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
ID: 24330356
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
ID: 24332811
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
ID: 24333001
" 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

808 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