[AccessD] Dynamically calling combobox_afterupdate from form_open event

Ryan W wrwehler at gmail.com
Thu Mar 9 11:34:33 CST 2023


Here's a demo file for using Eval:

https://drive.google.com/file/d/15fZdLS850PSHOAQmYSiIKdp7bkgSBwGl/view?usp=sharing

Open Form1, press the button and look in your VBA immediate window.  It
just called 10 public functions (in Module1)


On Wed, Mar 8, 2023 at 2:51 PM John Colby <jwcolby at gmail.com> wrote:

> The functions I sent were out in a public module.  I tried the eval thing
> out there and it still didn't work.  Or I never got it to work anyway.
>
> On Tue, Mar 7, 2023 at 7:22 PM Ryan W <wrwehler at gmail.com> wrote:
>
> > I think it was that Stuart mentioned the public functions have to be in a
> > module and not a form codebehind for Eval to work.  So…. I just made a
> > select case to run what’s needed as the loop comes across the key/value
> > pair.
> >
> >
> >
> > Sent from my iPhone
> >
> > > On Mar 7, 2023, at 5:52 PM, John Colby <jwcolby at gmail.com> wrote:
> > >
> > > I am having no more success than you using the eval function. 🤕
> > >
> > >> On Tue, Mar 7, 2023 at 4:36 PM John Colby <jwcolby at gmail.com> wrote:
> > >>
> > >>
> > >>
> >
> https://stackoverflow.com/questions/1072075/call-a-vba-function-into-a-sub-procedure
> > >>
> > >> From that it appears that you need to change the private declaration
> for
> > >> the event sink to public.
> > >>
> > >> After that I did the following:
> > >>
> > >> Create a module and generate two functions:
> > >>
> > >> Function CallIt(str As String)
> > >> Dim frm As Form
> > >>
> > >>    Set frm = Forms("FrmLocation")
> > >>    frm.Form_Current
> > >> End Function
> > >>
> > >> Function CallIt2(str As String)
> > >>    'Call Forms("frmLocation").Form_Current
> > >>    Call Forms("frmLocation").txtName_AfterUpdate
> > >> End Function
> > >>
> > >> Both of these work IF the event sink is public.
> > >>
> > >> You can now call these functions from anywhere including from inside
> of
> > >> the form.  Pass the event name into the function and mess around with
> > using
> > >> that passed in string.  Like trying your eval() thingie.
> > >>
> > >> Hey you gotta do some of the work!  ;)
> > >>
> > >>
> > >>
> > >>
> > >>> On Mon, Mar 6, 2023 at 2:03 PM Ryan W <wrwehler at gmail.com> wrote:
> > >>>
> > >>> I have a form that takes openargs, the openargs are such as:
> > >>>
> > >>> cbxJobID|12345
> > >>>
> > >>>
> > >>> The key/pair set can be repeated.. the key is the control name, the
> > other
> > >>> is the data to input into the control name
> > >>>
> > >>> my form open event is as such:
> > >>>
> > >>> Private Sub Form_Open(Cancel As Integer)
> > >>>    Dim l         As Long: l = 0
> > >>>    Dim strArgs() As String
> > >>>    If IsNull(Me.OpenArgs) Then Exit Sub
> > >>>
> > >>>    strArgs = Split(Me.OpenArgs, "|")
> > >>>    For l = 0 To UBound(strArgs) Step 2
> > >>>        Me(strArgs(l)) = strArgs(l + 1)
> > >>>        Call Eval(strArgs(l) & "_AfterUpdate")
> > >>>    Next l
> > >>>
> > >>> End Sub
> > >>>
> > >>>
> > >>>
> > >>> The problem I'm having is the "Call Eval()" part.  I get an error:
> > >>> "Run-Time error '2482':
> > >>> Cannot find name 'cbxJobID_AfterUpdate' you entered in the
> expression.
> > >>>
> > >>> However that exists.  I've tried making it a public sub, private sub,
> > >>> public or private function.
> > >>>
> > >>> None of it seems to work. Maybe it can't be a form level
> function/sub,
> > has
> > >>> to be module level?
> > >>>
> > >>> The microsoft documentation under examples shows the method I'm using
> > is
> > >>> supported:
> > >>>
> > >>>
> > https://learn.microsoft.com/en-us/office/vba/api/access.application.eval
> > >>>
> > >>>
> > >>> The following example assumes that you have a series of 50 functions
> > >>> defined as A1, A2, and so on. This example uses the *Eval* function
> to
> > >>> call
> > >>> each function in the series.
> > >>> Sub CallSeries()
> > >>>
> > >>> Dim intI As Integer
> > >>>
> > >>> For intI = 1 To 50
> > >>> Eval("A" & intI & "()")
> > >>> Next intI
> > >>>
> > >>> End Sub
> > >>>
> > >>>
> > >>> So, something is missing here... can anyone clue me in?
> > >>> --
> > >>> AccessD mailing list
> > >>> AccessD at databaseadvisors.com
> > >>> https://databaseadvisors.com/mailman/listinfo/accessd
> > >>> Website: http://www.databaseadvisors.com
> > >>>
> > >>
> > >>
> > >> --
> > >> John W. Colby
> > >> Colby Consulting
> > >>
> > >
> > >
> > > --
> > > John W. Colby
> > > Colby Consulting
> > > --
> > > AccessD mailing list
> > > AccessD at databaseadvisors.com
> > > https://databaseadvisors.com/mailman/listinfo/accessd
> > > Website: http://www.databaseadvisors.com
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > https://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
>
>
> --
> John W. Colby
> Colby Consulting
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


More information about the AccessD mailing list