MS Access: list macro from VBA - ms-access

I have to deal with a few macros (not VBA) in an inherited Access application.
In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by the way Access does it.
Therefore I want to make my little piece of code to list the macros, their instructions list and parameters to the debug window or to a text file.
I googled but did not find much on what object(s) contain those macros.
Any clue to put me on track ?

Have you tried the built-in database documenter that will printout all of the macro code in one shot for you?
Go tools->analyze->documentor
This feature allows you to printout all macro code in the whole application

Related

Is it possible to run a VBA file from a VB6 application?

I have a very large amount of code written in VBA in Access .mdb files, containing forms and connecting to an Access data base. I need to migrate this code to a VB6 application. It isn't practical to rewrite all of it as there is just too much.
Is there a way to call that VBA file from a VB6 form with buttons, that would allow users to launch each one of these VBA modules, via a simple click on its corresponding button? What line of code in VB6, allows to launch a VBA file?
Update
I finally succeeded to figure out how to launch a VBA mdb file from my VB6 form using this instruction :
Call Shell("C:\Program Files (x86)\Microsoft Office\OFFICE11\MSACCESS.EXE C:\presto.mdb /runtime /cmd", 1)
So the VBA project is now launched from the VB6 form, but it crashes, at start up, showing this error "Runtime error ‘3024’ Could not find file ‘C:\db.mdb’".
I feel like I'm half way to thee solution. But I don't know what am I missing here?
Without knowing the structure of your VB6 application and your access files and what they do, it is virtually impossible to give any sort of useful answer.
What you want to do is not easily possible, as stated in comments VBA projects are not designed to work in this way.
However here are some suggestions.
Investigate the RunMacro command and see if this is of use to you.
You could try to use a tool like autohotkey to record mouse clicks where you want them and replay from your VB6 app.
Look at pulling out sections of VBA that are business logic and directly copy and paste code into your VB6 app. This may or may not work depending on the code.
Begin the slow process of rewriting (but don't rewrite in VB6, use VB.Net, C# or do a web app or something at least resembling a 2015 application).
If you want my honest advice begin to migrate to a more modern solution such as VB.NET so you won't have an even worse problem in 2020.
There is NO silver bullet for your problem.
It would be better to design a new form in VB6 with button as you said but also with some text(s)/list(s)/whatever(s) you want to display the results, then you copy/paste VBA code into button_click(s) event(s) to execute it and add to that vba code some output to the text(s)/list(s)/whatever(s) you decided to put on the VB6 form.
Edit : Ok, so taking your comment in consideration perhaps that trick could help avoiding re-write thousands of line code : add in the VBA code a while loop that trigger some Sub or Function on the presence of a flag on the system (a specific c:\temp\fileFlag.txt for example) so as soon as it appear the VBA code is called... if the VB6 control the flag would it do the job ? :)

Odd behaviour in MS Access

Right now I'm working on an application in access 2010 that generates letters based of data taken from a share point site. The user inputs some parameters from some combo boxes on a form. After the selection is made the user selects the type of letter they want by pressing a button.
This works fine but I'm experiencing an odd issue when I close access and reopen it later.
When I open the form after starting access again I'll attempt to create a letter but instead of working like it did before the criteria prompt window appears asking for a parameter instead of taking the form values.
This happens every-time I restart access and the way I've been fixing it is by changing the names of the combo-boxes and then adjusting the queries accordingly.
This is what i was using to get the form values in the query
Like [Forms]![Main Menu]![A] & "*" (A is the name of the combo box, I got tired of renaming it)
Any Idea whats going on because I'm at a loss.
Thanks in advance!
If you are 100% positive that Access is finding your parameters just fine, and when Access closes they are lost, then:
Do you have any backup copies of this database before the error
occurred? Can you use one of them?
Do you Compact & Repair the database every time you close it? This
can be used somewhat as "damage control," because MS Access does
have a tendency to become corrupt.
Make sure the Main Menu form is open as long as the query is
running. Does it close right away (aka the query isn't finding the
parameter because the form is closed)?
From searching around, it seems that you aren't the only person with this problem. A known fix for people seems to have been copying all objects into a new database (which to me, sounds like the database is corrupt.) This could also mean maybe only your form is corrupt. Perhaps try to create a new form that does all of the same things that your Main Menu form does.
I'm sorry there doesn't seem to be a 'clear-cut' definitive solution for your situation.
If any VBA is involved, see below:
If you use the "Database Documenter" feature and check "yes" to all the options, you will obtain an exhaustive report that should let you trap your problem parameter. Export this report as an .rtf or .pdf document, so it is searchable. Identify a keyword from the dialog prompt, and search on that.
Once you check the query objects using the Documenter, check your VBA code. You'll do this by stepping through code in the IDE. If the main form has subforms, they are opened with (within) the main form. And they load before the main form.
Identify those subforms.
Sprinkle breakpoints in their code modules (if you find a Load function, that is highly relevant).
If the main form has a code module, do the same there.
From this thread

Run vba code from within 2010 Data Macro

I have a function that creates a text file and need to run it from the data macro. so then the evens can use it on the table.
How do I go about doing this?
You don't, as per our chat. Data macros even run outside of MS Access, if they used code within MS Access, this could not happen. They are tied to the database engine, which knows nothing about Access front-end.
You can run queries from a data macro AFAIK, and it is possible to create a query to write to a file*, but you cannot run VBA.
* I looked into this a little more and I find: "Queries that contain linked tables, action queries, and database references are not allowed in data macros."
You can do this, but it not recommend. Remember, table triggers and store procedure code does run independent of VBA and in fact it runs even if you don't have Access installed.
However, assuming you going to be using Access to always edit the data (a reasonable assumption), then you can in fact have the table macro call VBA code. There are several ways of doing this, but the most common and useful is to set SetLocalVar to a VBA function. This has the added bonus of being able to pass some values to that function which in most cases is likely required.
So, keep in mind you can call VBA code, but then you are adding creating a dependence from your tables to VBA.
So just use SetLocalVar to some dummy var, and place the VBA function in the expression.

Where can I edit existing queries defined in Access 2007?

I'm having to do some maintenance on a Access 2007 application. I've never really used it before so I'm struggling to figure out where things are hidden. This application is broken up into two ACCDB's - one for the application, one with the data. Inside of the application I am attempting to track down where various queries are defined but not having much luck.
I've looked in the data ACCDB and selected the "Queries" category off the sidebar. The queries are not there. Inside of the Visual Basic editor of the application ACCDB, they also don't appear in the "Microsoft Office Access Class Objects".
If I click on "Create", then Query Design it seems to open a designer where I can select these queries. However, I still can't seem to figure out how to actually edit existing ones (which is what I really want to do).
Where on earth can I edit them?
On the sidebar on the left you can select different categories like Tables, Queries etc.; however, queries can also be stored in the RecordSource of Forms, Reports and the RowSource of controls. For instance ListBox and ComboBox have a RowSource property. Queries can be stored as SQL strings in VBA code or Macros or they can even be created dynamically with VBA.

Access 2007 - vba instead of Macro

I dont want the buttons to produces "embed macro" . I tries to press the convert icon to VBA , but still when i use the wizard of buttons it remains to be macro instead of vba procedure , why ?
thank you
Create a button without the wizard.
Right-click on the button and select Build Event. Choose "Code Builder"
The Microsoft Visual Basic IDE should open.
You can also access the buttons events from the Properties Sheet | Event tab.
Beginning with Access 2007, Microsoft built a stronger, more capable macro system that they hope will be able to mostly replace VBA due to the inherent security differences between VBA and macros. There is not, as of yet, a simple way to make Access 2007 or 2010 create VBA code instead of macros when using wizards.
There are two ways some people have had success getting Access to create VBA or converting macros to VBA.
Create an Access 2003 database (.mdb) file. This will create a db compatible with the older versions of Access that don't have the robust macro system and so the code created will be VBA for the most part. The drawbacks of this will be if other functions in your database require the newer Access functions.
After the macro is created, save it as a separate macro rather than an embedded macro. Then in the Design ribbon in the Tools group, the Convert Form's Macros to Visual Basic should work more reliably. The converter is still not very reliable, and if it errors out, there is usually not a way to fix the issue.