Get Form Event Code Programmatically

jdraw

Super Moderator
Staff member
Local time
Today, 17:26
Joined
Jan 23, 2006
Messages
15,586
Is there a way through vba to display a Form's OnLoad Event code? Does anyone have a sample? I'm using Acc2003 on XP.

I have code to find a Form's Recordsource and Filter, but have not found a way to show Event code programmatically.

TIA.
 
Since I know you're pretty good at your programming I don't need you to justify why you want to do it so here:

http://www.cpearson.com/excel/vbe.aspx

Just out of curiousity, can you tell me why you want to do that? We may have other ideas for you.
 
vbaInet, It was just a thought for an approach. Someone on a forum has a large database, used by lot's of users. It has become somewhat disorganized. He has several forms and reports and has no idea (his words) which ones are used and which are no longer required. He didn't want to analyze each and every Form and Report manually.

My thinking was to go thru all Forms/Reports and insert some code into OnLoad or OnOpen to write the Form/Report name and Date to a logfile.

Scan the logfile. Do a compare with list of Forms and reports.

At least it would focus the work effort.

Thanks for responding.
 
Ok, cool!

I wouldn't do it via the editor. You can use the Expressions Builder instead and point that to a global function. For example:
Code:
Loop through Forms collection
    Open form in design view
    frm.OnLoad = "=[COLOR=blue]TheFunction()[/COLOR]"
    Close form and save
End Loop
But then again, you will loose any code that was already set in the Load event. So perhaps, your idea of editting the code is more viable.
 
Is it possible to create a Custom event and use that, so as to avoid any deletion of existing code?
 
Na, because you will need to hook the form to the event.

You can get the line number of the Load's End Sub and insert your code on that line. It should push the End Sub down. Either that or you use the line before.
 
Thanks, I think I'll post him the link to our conversation and let him decide.

Thanks for your assistance.
Orange
 

Users who are viewing this thread

Back
Top Bottom