Calling a Function using an array or variable 
Author Message
 Calling a Function using an array or variable

I am trying to create a generic report that on open of
the report it will run different functions where the sql
statement is stored.  The question is is there a way to
use an array or variable to call the different
functions.  I have created a table to store the report
names, report display name, function name, etc. and my
listbox is based on this table.  I have tried a global
variable and the Call does not recognize the variable as
an actual Function just a string ".....".  This method or
one similar is needed to meet the needs of the client.


Thu, 13 Oct 2005 02:09:01 GMT  
 Calling a Function using an array or variable
If the procedures to be run are defined as Functions, as opposed to
Subs, you should be able to use the Eval() function to evaluate a
string containing the function name -- so long as there are
parentheses on the end.  For example,

    Dim astrFunctions(2) As String

    astrFunctions(0) = "Function1"
    astrFunctions(1) = "Function2"
    astrFunctions(2) = "Function3"

    Eval astrFunctions(1) & "()"
    ' should call Function2

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Quote:
> I am trying to create a generic report that on open of
> the report it will run different functions where the sql
> statement is stored.  The question is is there a way to
> use an array or variable to call the different
> functions.  I have created a table to store the report
> names, report display name, function name, etc. and my
> listbox is based on this table.  I have tried a global
> variable and the Call does not recognize the variable as
> an actual Function just a string ".....".  This method or
> one similar is needed to meet the needs of the client.



Thu, 13 Oct 2005 15:28:04 GMT  
 Calling a Function using an array or variable
Thank you for responding to my question, however, I am
still confused.

What I am trying to accomplish is to eliminate the need to
actual list the functions within a particular sub
procedure.  I was hoping there was a way to use a string
that included the Name of the function to be called.  I
have created a maintenance table that will store the
Report name, Title, function fields.  It is
this "function" name field I would like to use and to Call
or Eval() to actual run the Function.  However, it is
still being passed as a string and not recognized as an
actual Function.
 Below are the samples of the code I have tried so far.  
Could you please point me in the right direction.

On the Form(listbox) for selection of the actual report:

 Private Sub Ctl1stReportList_Click()

On Error GoTo Err_Ctl1stReportList_Click

   If [1stReportList].Column(4) = True Then

        Me.lblBegDate.Visible = True

        Me.BegDate.Visible = True

        Me.lblEndDate.Visible = True

        Me.EndDate.Visible = True

        Me.BegDate.SetFocus

        Me.lblBegDate.BackColor = 8454143

        Me.BegDate.BackColor = 8454143

        gModName = [1stReportList].Column(6)

    Else

        Me.[1stReportList].SetFocus

        Me.lblBegDate.Visible = False

        Me.BegDate.Visible = False

        Me.lblEndDate.Visible = False

        Me.EndDate.Visible = False

    End If

    Eval GenerateReportFunc(gModName)

Exit_Ctl1stReportList_Click:

    On Error Resume Next

    Exit Sub

Err_Ctl1stReportList_Click:

    Select Case Err.Number

        Case 0

            Resume Exit_Ctl1stReportList_Click:

        Case Else

            MsgBox Err.Number & " " & Err.Description,
vbExclamation, "Error in module Form_frmPrintOptions - sub
Ctl1stReportList_Click"

            Resume Exit_Ctl1stReportList_Click:

    End Select

End Sub

The Function:

Public Function GenerateReportFunc()

'Comments  : Calls the specific function by name using a
variable string to run the Sql string for a specific
report.

'Developer : Karen Schaefer, Apexalon, INc.

'Created   : 4/25/2003 15:29

On Error GoTo Err_GenerateReportFunc

    Dim astrFunctions(2) As String

    astrFunctions(0) = "Function1"

    astrFunctions(1) = "Function2"

    astrFunctions(2) = "Function3"

  Does this require me actually listing the Function names
Which would defeat the purpose of passing the string name.

    Eval astrFunctions(1) & "()"

    ' should call Function2

    gModName = Forms![frmPrintOptions]!
[1stReportList].Column(5)

    str1 = Mid(gModName, 1, Len(gModName))

Exit_GenerateReportFunc:

    On Error Resume Next

    Exit Function

Err_GenerateReportFunc:

    Select Case Err.Number

        Case 0

            Resume Exit_GenerateReportFunc:

        Case Else

            MsgBox Err.Number & " " & Err.Description,
vbExclamation, "Error in module Module1 - function
GenerateReportFunc"

            Resume Exit_GenerateReportFunc:

    End Select

End Function
Actual Function Name : PastFutureRevenueSQL

Quote:
>-----Original Message-----
>If the procedures to be run are defined as Functions, as
opposed to
>Subs, you should be able to use the Eval() function to
evaluate a
>string containing the function name -- so long as there
are
>parentheses on the end.  For example,

>    Dim astrFunctions(2) As String

>    astrFunctions(0) = "Function1"
>    astrFunctions(1) = "Function2"
>    astrFunctions(2) = "Function3"

>    Eval astrFunctions(1) & "()"
>    ' should call Function2

>--
>Dirk Goldgar, MS Access MVP
>www.datagnostics.com

>(please reply to the newsgroup)



>> I am trying to create a generic report that on open of
>> the report it will run different functions where the sql
>> statement is stored.  The question is is there a way to
>> use an array or variable to call the different
>> functions.  I have created a table to store the report
>> names, report display name, function name, etc. and my
>> listbox is based on this table.  I have tried a global
>> variable and the Call does not recognize the variable as
>> an actual Function just a string ".....".  This method
or
>> one similar is needed to meet the needs of the client.

>.



Sat, 15 Oct 2005 00:29:06 GMT  
 Calling a Function using an array or variable
The code I posted was just by way of example;  you didn't need to
include it in your own routine.  Looking over the code you posted, I'm
a little bit confused by the way you're setting gModName from
1stReportList.Column(6) in Ctl1stReportList_Click(), then calling
GenerateReportFunc() which sets gModName from what I take to be
Column(5) of the same list box.  Which column has the function name,
Column(6) or Column(5)?

Although naturally I don't understand all the ramifications of your
application, you might start with something like this code for the
list box's Click event:

'----- start of suggested code -----
Private Sub Ctl1stReportList_Click()

    On Error GoTo Err_Ctl1stReportList_Click

    If Me.1stReportList.Column(4) = True Then

        Me.lblBegDate.Visible = True
        Me.BegDate.Visible = True
        Me.lblEndDate.Visible = True
        Me.EndDate.Visible = True
        Me.BegDate.SetFocus
        Me.lblBegDate.BackColor = 8454143
        Me.BegDate.BackColor = 8454143

        ' call the function whose name is in the
        ' list box's seventh column.
        Eval Me.1stReportList.Column(6) & "()"

    Else
        Me.1stReportList.SetFocus
        Me.lblBegDate.Visible = False
        Me.BegDate.Visible = False
        Me.lblEndDate.Visible = False
        Me.EndDate.Visible = False
    End If

Exit_Ctl1stReportList_Click:
    Exit Sub

Err_Ctl1stReportList_Click:

    Select Case Err.Number
        Case 0
            Resume Exit_Ctl1stReportList_Click

        Case Else

            MsgBox Err.Number & " " & Err.Description,
                vbExclamation, _
                "Error in module Form_frmPrintOptions - " & _
                "sub Ctl1stReportList_Click"

            Resume Exit_Ctl1stReportList_Click:

    End Select

End Sub

'----- end of suggested code -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Quote:
> Thank you for responding to my question, however, I am
> still confused.

> What I am trying to accomplish is to eliminate the need to
> actual list the functions within a particular sub
> procedure.  I was hoping there was a way to use a string
> that included the Name of the function to be called.  I
> have created a maintenance table that will store the
> Report name, Title, function fields.  It is
> this "function" name field I would like to use and to Call
> or Eval() to actual run the Function.  However, it is
> still being passed as a string and not recognized as an
> actual Function.
>  Below are the samples of the code I have tried so far.
> Could you please point me in the right direction.

> On the Form(listbox) for selection of the actual report:

>  Private Sub Ctl1stReportList_Click()

> On Error GoTo Err_Ctl1stReportList_Click

>    If [1stReportList].Column(4) = True Then

>         Me.lblBegDate.Visible = True

>         Me.BegDate.Visible = True

>         Me.lblEndDate.Visible = True

>         Me.EndDate.Visible = True

>         Me.BegDate.SetFocus

>         Me.lblBegDate.BackColor = 8454143

>         Me.BegDate.BackColor = 8454143

>         gModName = [1stReportList].Column(6)

>     Else

>         Me.[1stReportList].SetFocus

>         Me.lblBegDate.Visible = False

>         Me.BegDate.Visible = False

>         Me.lblEndDate.Visible = False

>         Me.EndDate.Visible = False

>     End If

>     Eval GenerateReportFunc(gModName)

> Exit_Ctl1stReportList_Click:

>     On Error Resume Next

>     Exit Sub

> Err_Ctl1stReportList_Click:

>     Select Case Err.Number

>         Case 0

>             Resume Exit_Ctl1stReportList_Click:

>         Case Else

>             MsgBox Err.Number & " " & Err.Description,
> vbExclamation, "Error in module Form_frmPrintOptions - sub
> Ctl1stReportList_Click"

>             Resume Exit_Ctl1stReportList_Click:

>     End Select

> End Sub

> The Function:

> Public Function GenerateReportFunc()

> 'Comments  : Calls the specific function by name using a
> variable string to run the Sql string for a specific
> report.

> 'Developer : Karen Schaefer, Apexalon, INc.

> 'Created   : 4/25/2003 15:29

> On Error GoTo Err_GenerateReportFunc

>     Dim astrFunctions(2) As String

>     astrFunctions(0) = "Function1"

>     astrFunctions(1) = "Function2"

>     astrFunctions(2) = "Function3"

>   Does this require me actually listing the Function names
> Which would defeat the purpose of passing the string name.

>     Eval astrFunctions(1) & "()"

>     ' should call Function2

>     gModName = Forms![frmPrintOptions]!
> [1stReportList].Column(5)

>     str1 = Mid(gModName, 1, Len(gModName))

> Exit_GenerateReportFunc:

>     On Error Resume Next

>     Exit Function

> Err_GenerateReportFunc:

>     Select Case Err.Number

>         Case 0

>             Resume Exit_GenerateReportFunc:

>         Case Else

>             MsgBox Err.Number & " " & Err.Description,
> vbExclamation, "Error in module Module1 - function
> GenerateReportFunc"

>             Resume Exit_GenerateReportFunc:

>     End Select

> End Function
> Actual Function Name : PastFutureRevenueSQL

> >-----Original Message-----
> >If the procedures to be run are defined as Functions, as
> opposed to
> >Subs, you should be able to use the Eval() function to
> evaluate a
> >string containing the function name -- so long as there
> are
> >parentheses on the end.  For example,

> >    Dim astrFunctions(2) As String

> >    astrFunctions(0) = "Function1"
> >    astrFunctions(1) = "Function2"
> >    astrFunctions(2) = "Function3"

> >    Eval astrFunctions(1) & "()"
> >    ' should call Function2

> >--
> >Dirk Goldgar, MS Access MVP
> >www.datagnostics.com

> >(please reply to the newsgroup)



> >> I am trying to create a generic report that on open of
> >> the report it will run different functions where the sql
> >> statement is stored.  The question is is there a way to
> >> use an array or variable to call the different
> >> functions.  I have created a table to store the report
> >> names, report display name, function name, etc. and my
> >> listbox is based on this table.  I have tried a global
> >> variable and the Call does not recognize the variable as
> >> an actual Function just a string ".....".  This method
> or
> >> one similar is needed to meet the needs of the client.

> >.



Sat, 15 Oct 2005 02:45:23 GMT  
 Calling a Function using an array or variable
Small correction:  another line-continuation character is needed in
the MsgBox call in the error-handler.  This:

Quote:
>           MsgBox Err.Number & " " & Err.Description,
>               vbExclamation, _
>               "Error in module Form_frmPrintOptions - " & _
>               "sub Ctl1stReportList_Click"

should be this:

            MsgBox Err.Number & " " & Err.Description,
                vbExclamation, _
                "Error in module Form_frmPrintOptions - " & _
                "sub Ctl1stReportList_Click"

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Quote:
> The code I posted was just by way of example;  you didn't need to
> include it in your own routine.  Looking over the code you posted,
I'm
> a little bit confused by the way you're setting gModName from
> 1stReportList.Column(6) in Ctl1stReportList_Click(), then calling
> GenerateReportFunc() which sets gModName from what I take to be
> Column(5) of the same list box.  Which column has the function name,
> Column(6) or Column(5)?

> Although naturally I don't understand all the ramifications of your
> application, you might start with something like this code for the
> list box's Click event:

> '----- start of suggested code -----
> Private Sub Ctl1stReportList_Click()

>     On Error GoTo Err_Ctl1stReportList_Click

>     If Me.1stReportList.Column(4) = True Then

>         Me.lblBegDate.Visible = True
>         Me.BegDate.Visible = True
>         Me.lblEndDate.Visible = True
>         Me.EndDate.Visible = True
>         Me.BegDate.SetFocus
>         Me.lblBegDate.BackColor = 8454143
>         Me.BegDate.BackColor = 8454143

>         ' call the function whose name is in the
>         ' list box's seventh column.
>         Eval Me.1stReportList.Column(6) & "()"

>     Else
>         Me.1stReportList.SetFocus
>         Me.lblBegDate.Visible = False
>         Me.BegDate.Visible = False
>         Me.lblEndDate.Visible = False
>         Me.EndDate.Visible = False
>     End If

> Exit_Ctl1stReportList_Click:
>     Exit Sub

> Err_Ctl1stReportList_Click:

>     Select Case Err.Number
>         Case 0
>             Resume Exit_Ctl1stReportList_Click

>         Case Else

>             MsgBox Err.Number & " " & Err.Description,
>                 vbExclamation, _
>                 "Error in module Form_frmPrintOptions - " & _
>                 "sub Ctl1stReportList_Click"

>             Resume Exit_Ctl1stReportList_Click:

>     End Select

> End Sub

> '----- end of suggested code -----

> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com

> (please reply to the newsgroup)



> > Thank you for responding to my question, however, I am
> > still confused.

> > What I am trying to accomplish is to eliminate the need to
> > actual list the functions within a particular sub
> > procedure.  I was hoping there was a way to use a string
> > that included the Name of the function to be called.  I
> > have created a maintenance table that will store the
> > Report name, Title, function fields.  It is
> > this "function" name field I would like to use and to Call
> > or Eval() to actual run the Function.  However, it is
> > still being passed as a string and not recognized as an
> > actual Function.
> >  Below are the samples of the code I have tried so far.
> > Could you please point me in the right direction.

> > On the Form(listbox) for selection of the actual report:

> >  Private Sub Ctl1stReportList_Click()

> > On Error GoTo Err_Ctl1stReportList_Click

> >    If [1stReportList].Column(4) = True Then

> >         Me.lblBegDate.Visible = True

> >         Me.BegDate.Visible = True

> >         Me.lblEndDate.Visible = True

> >         Me.EndDate.Visible = True

> >         Me.BegDate.SetFocus

> >         Me.lblBegDate.BackColor = 8454143

> >         Me.BegDate.BackColor = 8454143

> >         gModName = [1stReportList].Column(6)

> >     Else

> >         Me.[1stReportList].SetFocus

> >         Me.lblBegDate.Visible = False

> >         Me.BegDate.Visible = False

> >         Me.lblEndDate.Visible = False

> >         Me.EndDate.Visible = False

> >     End If

> >     Eval GenerateReportFunc(gModName)

> > Exit_Ctl1stReportList_Click:

> >     On Error Resume Next

> >     Exit Sub

> > Err_Ctl1stReportList_Click:

> >     Select Case Err.Number

> >         Case 0

> >             Resume Exit_Ctl1stReportList_Click:

> >         Case Else

> >             MsgBox Err.Number & " " & Err.Description,
> > vbExclamation, "Error in module Form_frmPrintOptions - sub
> > Ctl1stReportList_Click"

> >             Resume Exit_Ctl1stReportList_Click:

> >     End Select

> > End Sub

> > The Function:

> > Public Function GenerateReportFunc()

> > 'Comments  : Calls the specific function by name using a
> > variable string to run the Sql string for a specific
> > report.

> > 'Developer : Karen Schaefer, Apexalon, INc.

> > 'Created   : 4/25/2003 15:29

> > On Error GoTo Err_GenerateReportFunc

> >     Dim astrFunctions(2) As String

> >     astrFunctions(0) = "Function1"

> >     astrFunctions(1) = "Function2"

> >     astrFunctions(2) = "Function3"

> >   Does this require me actually listing the Function names
> > Which would defeat the purpose of passing the string name.

> >     Eval astrFunctions(1) & "()"

> >     ' should call Function2

> >     gModName = Forms![frmPrintOptions]!
> > [1stReportList].Column(5)

> >     str1 = Mid(gModName, 1, Len(gModName))

> > Exit_GenerateReportFunc:

> >     On Error Resume Next

> >     Exit Function

> > Err_GenerateReportFunc:

> >     Select Case Err.Number

> >         Case 0

> >             Resume Exit_GenerateReportFunc:

> >         Case Else

> >             MsgBox Err.Number & " " & Err.Description,
> > vbExclamation, "Error in module Module1 - function
> > GenerateReportFunc"

> >             Resume Exit_GenerateReportFunc:

> >     End Select

> > End Function
> > Actual Function Name : PastFutureRevenueSQL

> > >-----Original Message-----
> > >If the procedures to be run are defined as Functions, as
> > opposed to
> > >Subs, you should be able to use the Eval() function to
> > evaluate a
> > >string containing the function name -- so long as there
> > are
> > >parentheses on the end.  For example,

> > >    Dim astrFunctions(2) As String

> > >    astrFunctions(0) = "Function1"
> > >    astrFunctions(1) = "Function2"
> > >    astrFunctions(2) = "Function3"

> > >    Eval astrFunctions(1) & "()"
> > >    ' should call Function2

> > >--
> > >Dirk Goldgar, MS Access MVP
> > >www.datagnostics.com

> > >(please reply to the newsgroup)



> > >> I am trying to create a generic report that on open of
> > >> the report it will run different functions where the sql
> > >> statement is stored.  The question is is there a way to
> > >> use an array or variable to call the different
> > >> functions.  I have created a table to store the report
> > >> names, report display name, function name, etc. and my
> > >> listbox is based on this table.  I have tried a global
> > >> variable and the Call does not recognize the variable as
> > >> an actual Function just a string ".....".  This method
> > or
> > >> one similar is needed to meet the needs of the client.

> > >.



Sat, 15 Oct 2005 02:49:03 GMT  
 Calling a Function using an array or variable
AARRGH!  My "correction" didn't include the correction!  Let me try
again.  This:

Quote:
>           MsgBox Err.Number & " " & Err.Description,
>               vbExclamation, _
>               "Error in module Form_frmPrintOptions - " & _
>               "sub Ctl1stReportList_Click"

should be this:

            MsgBox Err.Number & " " & Err.Description, _
                vbExclamation, _
                "Error in module Form_frmPrintOptions - " & _
                "sub Ctl1stReportList_Click"

Sorry!
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


Quote:
> Small correction:  another line-continuation character is needed in
> the MsgBox call in the error-handler.  This:

> >           MsgBox Err.Number & " " & Err.Description,
> >               vbExclamation, _
> >               "Error in module Form_frmPrintOptions - " & _
> >               "sub Ctl1stReportList_Click"

> should be this:

>             MsgBox Err.Number & " " & Err.Description,
>                 vbExclamation, _
>                 "Error in module Form_frmPrintOptions - " & _
>                 "sub Ctl1stReportList_Click"

> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com

> (please reply to the newsgroup)



> > The code I posted was just by way of example;  you didn't need to
> > include it in your own routine.  Looking over the code you posted,
> I'm
> > a little bit confused by the way you're setting gModName from
> > 1stReportList.Column(6) in Ctl1stReportList_Click(), then calling
> > GenerateReportFunc() which sets gModName from what I take to be
> > Column(5) of the same list box.  Which column has the function
name,
> > Column(6) or Column(5)?

> > Although naturally I don't understand all the ramifications of
your
> > application, you might start with something like this code for the
> > list box's Click event:

> > '----- start of suggested code -----
> > Private Sub Ctl1stReportList_Click()

> >     On Error GoTo Err_Ctl1stReportList_Click

> >     If Me.1stReportList.Column(4) = True Then

> >         Me.lblBegDate.Visible = True
> >         Me.BegDate.Visible = True
> >         Me.lblEndDate.Visible = True
> >         Me.EndDate.Visible = True
> >         Me.BegDate.SetFocus
> >         Me.lblBegDate.BackColor = 8454143
> >         Me.BegDate.BackColor = 8454143

> >         ' call the function whose name is in the
> >         ' list box's seventh column.
> >         Eval Me.1stReportList.Column(6) & "()"

> >     Else
> >         Me.1stReportList.SetFocus
> >         Me.lblBegDate.Visible = False
> >         Me.BegDate.Visible = False
> >         Me.lblEndDate.Visible = False
> >         Me.EndDate.Visible = False
> >     End If

> > Exit_Ctl1stReportList_Click:
> >     Exit Sub

> > Err_Ctl1stReportList_Click:

> >     Select Case Err.Number
> >         Case 0
> >             Resume Exit_Ctl1stReportList_Click

> >         Case Else

> >             MsgBox Err.Number & " " & Err.Description,
> >                 vbExclamation, _
> >                 "Error in module Form_frmPrintOptions - " & _
> >                 "sub Ctl1stReportList_Click"

> >             Resume Exit_Ctl1stReportList_Click:

> >     End Select

> > End Sub

> > '----- end of suggested code -----

> > --
> > Dirk Goldgar, MS Access MVP
> > www.datagnostics.com

> > (please reply to the newsgroup)



> > > Thank you for responding to my question, however, I am
> > > still confused.

> > > What I am trying to accomplish is to eliminate the need to
> > > actual list the functions within a particular sub
> > > procedure.  I was hoping there was a way to use a string
> > > that included the Name of the function to be called.  I
> > > have created a maintenance table that will store the
> > > Report name, Title, function fields.  It is
> > > this "function" name field I would like to use and to Call
> > > or Eval() to actual run the Function.  However, it is
> > > still being passed as a string and not recognized as an
> > > actual Function.
> > >  Below are the samples of the code I have tried so far.
> > > Could you please point me in the right direction.

> > > On the Form(listbox) for selection of the actual report:

> > >  Private Sub Ctl1stReportList_Click()

> > > On Error GoTo Err_Ctl1stReportList_Click

> > >    If [1stReportList].Column(4) = True Then

> > >         Me.lblBegDate.Visible = True

> > >         Me.BegDate.Visible = True

> > >         Me.lblEndDate.Visible = True

> > >         Me.EndDate.Visible = True

> > >         Me.BegDate.SetFocus

> > >         Me.lblBegDate.BackColor = 8454143

> > >         Me.BegDate.BackColor = 8454143

> > >         gModName = [1stReportList].Column(6)

> > >     Else

> > >         Me.[1stReportList].SetFocus

> > >         Me.lblBegDate.Visible = False

> > >         Me.BegDate.Visible = False

> > >         Me.lblEndDate.Visible = False

> > >         Me.EndDate.Visible = False

> > >     End If

> > >     Eval GenerateReportFunc(gModName)

> > > Exit_Ctl1stReportList_Click:

> > >     On Error Resume Next

> > >     Exit Sub

> > > Err_Ctl1stReportList_Click:

> > >     Select Case Err.Number

> > >         Case 0

> > >             Resume Exit_Ctl1stReportList_Click:

> > >         Case Else

> > >             MsgBox Err.Number & " " & Err.Description,
> > > vbExclamation, "Error in module Form_frmPrintOptions - sub
> > > Ctl1stReportList_Click"

> > >             Resume Exit_Ctl1stReportList_Click:

> > >     End Select

> > > End Sub

> > > The Function:

> > > Public Function GenerateReportFunc()

> > > 'Comments  : Calls the specific function by name using a
> > > variable string to run the Sql string for a specific
> > > report.

> > > 'Developer : Karen Schaefer, Apexalon, INc.

> > > 'Created   : 4/25/2003 15:29

> > > On Error GoTo Err_GenerateReportFunc

> > >     Dim astrFunctions(2) As String

> > >     astrFunctions(0) = "Function1"

> > >     astrFunctions(1) = "Function2"

> > >     astrFunctions(2) = "Function3"

> > >   Does this require me actually listing the Function names
> > > Which would defeat the purpose of passing the string name.

> > >     Eval astrFunctions(1) & "()"

> > >     ' should call Function2

> > >     gModName = Forms![frmPrintOptions]!
> > > [1stReportList].Column(5)

> > >     str1 = Mid(gModName, 1, Len(gModName))

> > > Exit_GenerateReportFunc:

> > >     On Error Resume Next

> > >     Exit Function

> > > Err_GenerateReportFunc:

> > >     Select Case Err.Number

> > >         Case 0

> > >             Resume Exit_GenerateReportFunc:

> > >         Case Else

> > >             MsgBox Err.Number & " " & Err.Description,
> > > vbExclamation, "Error in module Module1 - function
> > > GenerateReportFunc"

> > >             Resume Exit_GenerateReportFunc:

> > >     End Select

> > > End Function
> > > Actual Function Name : PastFutureRevenueSQL

> > > >-----Original Message-----
> > > >If the procedures to be run are defined as Functions, as
> > > opposed to
> > > >Subs, you should be able to use the Eval() function to
> > > evaluate a
> > > >string containing the function name -- so long as there
> > > are
> > > >parentheses on the end.  For example,

> > > >    Dim astrFunctions(2) As String

> > > >    astrFunctions(0) = "Function1"
> > > >    astrFunctions(1) = "Function2"
> > > >    astrFunctions(2) = "Function3"

> > > >    Eval astrFunctions(1) & "()"
> > > >    ' should call Function2

> > > >--
> > > >Dirk Goldgar, MS Access MVP
> > > >www.datagnostics.com

> > > >(please reply to the newsgroup)



> > > >> I am trying to create a generic report that on open of
> > > >> the report it will run different functions where the sql
> > > >> statement is stored.  The question is is there a way to
> > > >> use an array or variable to call the different
> > > >> functions.  I have created a table to store the report
> > > >> names, report display name, function name, etc. and my
> > > >> listbox is based on this table.  I have tried a global
> > > >> variable and the Call does not recognize the variable as
> > > >> an actual Function just a string ".....".  This method
> > > or
> > > >> one similar is needed to meet the needs of the client.

> > > >.



Sat, 15 Oct 2005 02:51:35 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Calling function or sub with variable array or string names

2. Problem using an array in a function called by an update query

3. Using matrix functions with an array variable...

4. Help Using Variable To Call a Procedure or function

5. Help with using names and variables in a function call

6. using variable to call function/sun

7. Calling A Function Using A Variable

8. Call Function using Func Name stored in variable

9. Calling a function from an Array of functions

10. Using an Array Formula Function with Indirect Function to retrieve Linked data from another Excel Spreadsheet


 
Powered by phpBB® Forum Software © phpBB Group