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

Bill Benson bensonforums at gmail.com
Wed Mar 25 21:22:09 CDT 2015


Does vba extensibility work for Access objects, Ie.

Dim vbc as vbComponent
For each vbc in currentdb.vbproject or some such?
On Mar 25, 2015 10:06 AM, "jack drawbridge" <jackandpat.d at gmail.com> wrote:

> Jim, Thanks for the info.
>
> I see the mdl.CountOfLines etc and  mdl.InsertLines.
> Is there something to simply debug.print mdl  current line or loop to print
> lines??
>
> On Wed, Mar 25, 2015 at 9:23 AM, Jim Dettman <jimdettman at verizon.net>
> wrote:
>
> > Jack,
> >
> >  Also note you have the AddFromFile and AddFromString methods.  The first
> > was the forerunner to the current SaveAsText/LoadFromText
> >
> >  However this doesn't deal with the whole form, just the code.  Also note
> > that for much of this, the form needs to be open in design view.
> >
> > Jim.
> >
> > -----Original Message-----
> > From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
> > jack drawbridge
> > Sent: Wednesday, March 25, 2015 09:00 AM
> > To: Access Developers discussion and problem solving
> > Subject: Re: [AccessD] Sample vba to get code (event
> > procedurecode)behindform/controls
> >
> > 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
> > >
> > --
> > 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