[AccessD] Sample vba to get code (event procedure code)behindform/controls

jack drawbridge jackandpat.d at gmail.com
Wed Mar 25 08:00:15 CDT 2015


Thanks Jim. I'll give that a try. The SaveAsText/LoadAsText will serve my
purpose,  but if I can get right at the module, even better. Nice to have a
few options regardless.
Thanks.
jack

On Wed, Mar 25, 2015 at 8:42 AM, Jim Dettman <jimdettman at verizon.net> wrote:

> Jack,
>
> You need a reference to the module:
>
> Dim mdl As Module
> Set mdl = Modules!Form_Employees
>
> Or if the form/report is already open, you can do:
>
> Dim mdl As Module
> Set mdl = Forms!Employees.Module
>
>   Once you've done that, you can then use any of the module object methods,
> such as InsertLines, InsertText, ReplaceLine, etc.  Example:
>
> Function ClickEventProc() As Boolean
>         Dim frm As Form, ctl As Control, mdl As Module
>         Dim lngReturn As Long
>
>         On Error GoTo Error_ClickEventProc
>         ' Create new form.
>         Set frm = CreateForm
>         ' Create command button on form.
>         Set ctl = CreateControl(frm.Name, acCommandButton, , , , 1000,
> 1000)
>         ctl.Caption = "Click here"
>         ' Return reference to form module.
>         Set mdl = frm.Module
>         ' Add event procedure.
>         lngReturn = mdl.CreateEventProc("Click", ctl.Name)
>
> ' Insert text into body of procedure.
>         mdl.InsertLines lngReturn + 1, vbTab & "MsgBox ""Way cool!"""
>         ClickEventProc = True
>
> Exit_ClickEventProc:
>         Exit Function
>
> Error_ClickEventProc:
>         MsgBox Err & " :" & Err.Description
>         ClickEventProc = False
>         Resume Exit_ClickEventProc
> End Function
>
> Jim.
>
> -----Original Message-----
> From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
> jack drawbridge
> Sent: Tuesday, March 24, 2015 11:26 PM
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] Sample vba to get code (event procedure
> code)behindform/controls
>
> Right, it does. But it will work for what I'm trying.
> Save the form and code; insert some lines in each proc;
> then reload from revised text.
> Thanks again.
>
> On Tue, Mar 24, 2015 at 10:51 PM, Bill Benson <bensonforums at gmail.com>
> wrote:
>
> > That gets a lot more than code right?
> > On Mar 24, 2015 9:11 PM, "jack drawbridge" <jackandpat.d at gmail.com>
> wrote:
> >
> > > Thanks Stuart and Bill,
> > >
> > > Yes SaveAsText/LoadAsText are probably best suited (easiest).
> > >
> > > Thanks for the quick response.
> > > jack
> > >
> > > On Tue, Mar 24, 2015 at 8:55 PM, Bill Patten <
> bill_patten at embarqmail.com
> > >
> > > wrote:
> > >
> > > > Jack,
> > > >
> > > > I'm not sure I understand the question but If you want to export the
> > code
> > > > and controls behind a form
> > > > use SaveAsText
> > > > SaveAsText acForm, FormName as String, FileName as String
> > > >
> > > > Example SaveAsText "frmMain", "C:\FrmMain.txt"  to save the form in
> > your
> > > c:
> > > > directory.
> > > >
> > > > Bill
> > > >
> > > > -----Original Message-----
> > > > From: jack drawbridge
> > > > Sent: Tuesday, March 24, 2015 5:30 PM
> > > > To: Access Developers discussion and problem solving
> > > > Subject: [AccessD] Sample vba to get code (event procedure code)
> > > > behindform/controls
> > > >
> > > > Does anyone have some sample code showing how, using vba, to get the
> > code
> > > > behind a form and its controls? I have code to get standard
> > > > module/procedure lines, but have been unable to find any code (or any
> > > real
> > > > info really) on how to get that code.
> > > >
> > > > Any advice and guidance  most appreciated.
> > > >
> > > > Thanks in advance,
> > > > jack
> > > > --
> > > > AccessD mailing list
> > > > AccessD at databaseadvisors.com
> > > > http://databaseadvisors.com/mailman/listinfo/accessd
> > > > Website: http://www.databaseadvisors.com
> > > >
> > > > --
> > > > AccessD mailing list
> > > > AccessD at databaseadvisors.com
> > > > http://databaseadvisors.com/mailman/listinfo/accessd
> > > > Website: http://www.databaseadvisors.com
> > > >
> > > --
> > > AccessD mailing list
> > > AccessD at databaseadvisors.com
> > > http://databaseadvisors.com/mailman/listinfo/accessd
> > > Website: http://www.databaseadvisors.com
> > >
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > http://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


More information about the AccessD mailing list