Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Old 10-07-2011, 05:33 AM   #1
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,238
Thanks: 93
Thanked 2,026 Times in 1,973 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Get Form Event Code Programmatically

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.

jdraw is offline   Reply With Quote
Old 10-07-2011, 06:03 AM   #2
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,423 Times in 2,389 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: Get Form Event Code Programmatically

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 is offline   Reply With Quote
Old 10-07-2011, 06:09 AM   #3
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,238
Thanks: 93
Thanked 2,026 Times in 1,973 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Get Form Event Code Programmatically

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.

jdraw is offline   Reply With Quote
Old 10-07-2011, 06:18 AM   #4
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,423 Times in 2,389 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: Get Form Event Code Programmatically

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 = "=TheFunction()"
    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.
vbaInet is offline   Reply With Quote
Old 10-07-2011, 06:21 AM   #5
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,238
Thanks: 93
Thanked 2,026 Times in 1,973 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Get Form Event Code Programmatically

Is it possible to create a Custom event and use that, so as to avoid any deletion of existing code?
jdraw is offline   Reply With Quote
Old 10-07-2011, 06:27 AM   #6
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,423 Times in 2,389 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: Get Form Event Code Programmatically

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.
vbaInet is offline   Reply With Quote
Old 10-07-2011, 06:30 AM   #7
jdraw
Super Moderator
 
jdraw's Avatar
 
Join Date: Jan 2006
Location: Ottawa, Ontario, Canada;West Palm Beach, Florida
Posts: 12,238
Thanks: 93
Thanked 2,026 Times in 1,973 Posts
jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light jdraw is a glorious beacon of light
Re: Get Form Event Code Programmatically

Thanks, I think I'll post him the link to our conversation and let him decide.

Thanks for your assistance.
Orange

jdraw is offline   Reply With Quote
Old 10-07-2011, 06:32 AM   #8
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,423 Times in 2,389 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: Get Form Event Code Programmatically

No problemo!

vbaInet is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Run Event Code Of Another Form wazza Modules & VBA 30 07-26-2016 04:04 AM
Programmatically Add Event Procedure mbreu996 Modules & VBA 7 03-23-2010 01:08 PM
How to programmatically through VB Code change the system date/time format accesser2003 General 7 02-15-2010 10:17 AM
More Code for Form Event sclark Forms 3 02-26-2008 12:28 PM
trouble deleting with code during on click event of sub form pb21 Modules & VBA 1 05-13-2005 11:04 AM




All times are GMT -8. The time now is 12:31 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World