[AccessD] Application.Run not passing my arguments declared optionally

Bill Benson bensonforums at gmail.com
Sat Apr 12 22:03:11 CDT 2014


Works fine... that is what I did.

Private Sub Form_Load()
    Select Case Nz(DLookup("Function", "TblRestartFunctions"), "")
    Case Is = "Routine1": Application.Run "Routine1", True
    'ALTERNATIVE 'Case Is = "Routine1": x = Eval("Routine1" & " (True)")
    Case Is = "Routine2": Application.Run "Routine2", vbNull, True 'Thanks
Stuart M.
    'ALTERNATIVE Case Is = "Routine2": x = Eval("Routine2" & "
(False,True)")
    End Select
    CurrentDb.Execute "Delete * from TblRestartFunctions"
End If
End Sub

A thorny problem is how to pass objects and other argument types, having
first read them and their values from my table of function names and
arguments. I think I can do this...

As a for instance, if for Function X, there were 3 arguments of class
Boolean, String, and Tabledef, I could store in fields named  Arg1Type,
Arg2Type, Arg3 Type, ..., Arg6 Type, the values: "Boolean", "String",
"Tabledef", "#N/A", "#N/A", "#N/A" and in fields named Arg1Value, Arg2Value,
Arg3Value, Arg4Value, Arg5Value, Arg6Value, the values "True", "Bill",
"TblCompany"... 

And in my routine that looks up and wants to use this info, I could have a
Select Case which assigns variants to whatever is required according to that
ArgnType.
Select Case Nz(DLookup("Arg1Type", "TblRestartFunctions"), "")
Case is = "Boolean"
   VarArg1Value = CBool(Nz(DLookup("Arg1Value", "TblRestartFunctions"),
False)
Case is = "String"
   VarArg1Value = CBool(Nz(DLookup("Arg1Value", "TblRestartFunctions"),
"""")
Case is = "Tabledef"
   Set VarArg1Value = currentdb.tabledefs(Nz(DLookup("Arg1Value",
"TblRestartFunctions"), """"))
'''Possibly a few more types and assignment options
Case Else
   Set VarArg1Value =Empty
End Select

'... Repeat for Args2 thru 6 Type and Value, possibly with more items in the
Select Case

HOWEVER ... Using Application.Run, I think I should be able to pass the
VarArg1Value, VarArg2Value, etc...


Function Routine2(Optional T, Optional Restarted)
If Not IsMissing(Restarted) Then
    MsgBox "restarted is " & CBool(Restarted)
    GoTo Afterwards
Else
    MsgBox "restarted is False"
End If
MsgBox "Before Routine2,  my database size is " &
Format(FileLen(CurrentDb.Name), "#,###")

'Do some real work involving parameter T
GoTo exit_me

Afterwards:
MsgBox "Main parts of Routine2 were bypassed because we just wanted to check
the size after compaction, it is " & Format(FileLen(CurrentDb.Name),
"#,###")

exit_me:
End Function

Function Routine1(Optional Restarted)
If Not IsMissing(Restarted) Then
    MsgBox "restarted is " & CBool(Restarted)
    GoTo Afterwards
Else
    MsgBox "restarted is False"
End If
MsgBox "Before Routine1,  my database size is " &
Format(FileLen(CurrentDb.Name), "#,###")

'Do some real work
GoTo exit_me

Afterwards:
MsgBox "Main parts of Routine1 were bypassed because we just wanted to check
the size after compaction, it is " & Format(FileLen(CurrentDb.Name),
"#,###")

exit_me:
End Function

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
Sent: Saturday, April 12, 2014 10:34 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Application.Run not passing my arguments declared
optionally

After doing a bit of testing, it certainly looks like a limitation on
Application.Run (guess they 
were too busy creating multivalue fields etc to make it work properly).

I'd consider going with a wrapper function with a SELECT CASE block and
specifically calling 
a function depending on the input parameter.




More information about the AccessD mailing list