[AccessD] Pseudo Pointer to a Function

David McAfee davidmcafee at gmail.com
Tue Jun 23 12:26:12 CDT 2009


Concatenate the function name with any paremeters then call it in an eval
as such:



Public Function Test(Optional strtest As String, Optional strFuncName As
String) As Integer
Dim strC
If Nz(strFuncName, "") <> "" Then
    If strtest = "21040" Then
        'Test = GetCompanyIDByRamcoID(strtest)
        strC = strFuncName & "(" & NZ(strtest,"0") & ")"
        Test = Eval(strC)
    Else
        Test = 0
    End If
Else
    Test = 0
End If
End Function



Public Function GetCompanyIDByRamcoID(Optional RamcoID As String) As Integer
    Dim RtnStr As String
    If Nz(RamcoID, "") <> "" Then
         Dim rs As ADODB.Recordset
         Set rs = New ADODB.Recordset
         'Call the stored procedure, passing it the parameter, returning
recordset rs
         'CurrentProject.Connection.stpGetCustInfo CustNo, rs
         CurrentProject.Connection.stpGetCompanyIDbyRamcoID RamcoID, rs
         'Fill in the fields from the returned recordset
         If Not rs.BOF And Not rs.EOF Then
             RtnStr = IIf(Nz(rs![CompanyID], 0) = "", 0, rs![CompanyID])
         Else
             RtnStr = 0
         End If

         rs.Close
         Set rs = Nothing
    Else
        RtnStr = 0
    End If
     GetCompanyIDByRamcoID = RtnStr
End Function



On Tue, Jun 23, 2009 at 8:24 AM, Arthur Fuller <fuller.artful at gmail.com>wrote:

> Is there a way to pass the name of a function or procedure to another one?
> The need for this might occur when the given procedure must branch in
> various ways, and call a proc/function whose name depends upon the
> code-path, as it were. Yes, one could write a CASE statement to deal with
> this, and that is exactly what my current code does. But it set me to
> wonder
> whether it's possible to pass the name of the function/procedure to call
> rather than code the CASE statement.
> A.
> --
> 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