473,387 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Programmatic Extraction of VBA Code attached to Form Controls in Access

Hi, I am trying to pull together all of the VBA code I have written into a single document.

I have worked out how to programmatically list all modules and "print" the code contained within using the Modules Object but code that sits behind buttons etc within a Form is proving elusive.

Possibly a bit obscure and I guess I could copy and paste but that would be deeply unsatisfying!!

Many Thanks in anticipation
Phil
Mar 13 '14 #1
7 1684
zmbd
5,501 Expert Mod 4TB
Phil,
They started making it harder for VBA script to directly access the running code/script some years ago.

You can go in by hand and export each module.
You can use the database tools and the Database Documenter and selectively document the modules and forms.
You can use the CurrentProject.AllModules
loop thru each module, check for For Modules(strModule).CountOfLines, then loop thru the lines Modules(strModule).Lines appending to string our stdio file (see my insight article for stdio methods)

I usually just use the documenter tool as it covers enough for my company's needs.
Mar 13 '14 #2
jimatqsi
1,271 Expert 1GB
zmbd,
That sounds like a great tip. I have try that.

Jim
Mar 13 '14 #3
Many thanks ZMBD, I found the following works for code contained within modules:

Expand|Select|Wrap|Line Numbers
  1. Dim modOpenModules As Modules
  2. Dim mdl As Module
  3.  
  4. Set modOpenModules = Application.Modules
  5.  
  6. For i = 0 To modOpenModules.Count - 1
  7.   Module_Name = modOpenModules(i).Name
  8.   If Mid(Module_Name, 1, 5) <> "Form_" Then
  9.     docmd.OpenModule Module_Name
  10.     Set mdl = Modules(Module_Name)
  11.     For n = 1 To mdl.CountOfLines
  12.       Debug.Print mdl.Lines(n, 1)
  13.     Next
  14.   End If
  15. Next
  16.  
However modules with names beginning FORM_ had to be filtered out (as you see) because the OPENMODULE DOCMD would fail with a module not found condition!

I'd really like to be able to totally automate this process rather than wade through individual modules, forms etc but trying to locate the objects, methods or properties that enable it for "FORMS_xxxxx" type modules is not easy as you say! I do find navigating the MS documentation a challenge in itself!!

Best Regards
Phil
Mar 14 '14 #4
zmbd
5,501 Expert Mod 4TB
Try to open the form first in design mode, might check to see if it's loaded first. Once the form is opened, you shouldn't need to filter it out. Close the form once the stripping is done.
Mar 15 '14 #5
Hi ZMBD, an OpenModule request for a "FORM_module_name" fails with a module not found condition, so I guess there is something about FORM type module names that emerge from the MODULES collection that doesn't agree with the OpenModule method (Class modules vs Standard modules maybe - its still a vague area for me!).

But actually I am making progress with my understanding of the object system. You steered me toward the ALLMODULES and subsequently ALLFORMS, ALLQUERIES etc and the idea of collections in general to the point where I can now gather the names of code routines ([EVENT PROCEDURES] or SUBs) that are associated with form CONTROLs.

I suspect there must be some kind of object that represents these "[EVENT PROCEDURE]s" and can even see how I could create or modify such a procedure programatically using the INSERTLINES Method. Its the ability to read one that is still proving elusive!!

If I do succeed I'll post what I find here as it may be of interest to others from a purely acedemic point of view.

Once again, many thanks for your help.

Kind Rgds, Phil
Mar 15 '14 #6
zmbd
5,501 Expert Mod 4TB
Just a thought:

Rather than re-invent the wheel here, The built in database documenter does a fair job of documenting everything you're talking about so far...

I've also seen some code and applications (one I thing was freeware, others shareware) that already strip and analyze this information.
Mar 15 '14 #7
ZMBD, fantastic - thank you for that - I had never seen or used the documentor before. Looking in completely the wrong direction!

That will give me a solution for now if not entirely as slick as I was hoping for (a single click on a Form!). The documentor does show its possible to do and so I may keep pursuing it for purely acedemic reasons.

Best Rgds, Phil
Mar 15 '14 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John Hargrove | last post by:
I am building a database to manage test samples in an environmental laboratory. I am learning Access as I go and don't know much about the programming aspects. I hope to make the application...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
0
by: Lauren Quantrell | last post by:
In terms of resources, wondering if it makes a difference in adopting one of the three options below for resizing controls on a form and controls on a subform at the same time. option a.) Put...
3
by: Michael Ramey | last post by:
How can controls on a Windows Form be accessed (or referenced) from another Class? I know how to do it from another Form. The following doesn't work even though the Control Modifiers property is...
8
by: Ryan | last post by:
Ok.. I have a form with lots of stuff on it; a tool strip panel, menu strip, data binding elements (dataset, binding source, table adapter), tab control with 7 tab pages, each page contains a...
4
by: bUttA | last post by:
Hi guys, I'm new to using Access but have I some familiarity with databases in general. I have a quick question for the gurus here. I'm trying to work with a Form in Access that has a Calculated...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
0
NeoPa
by: NeoPa | last post by:
Introduction: We get fairly frequent questions on here about why settings (including both values AND formatting) of unbound controls on a form, are not stored for reference later, but instead, each...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
5
Seth Schrock
by: Seth Schrock | last post by:
I have created a navigation form in Access 2010 using the horizontal tabs, 2 levels style. This form is my startup form. In the top row, I have to options. Under each option are several sub-tabs...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.