Stuart McLachlan
stuart at lexacorp.com.pg
Sat Apr 12 21:34:10 CDT 2014
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.
On 12 Apr 2014 at 21:11, Bill Benson wrote:
> I got an alternative to "almost" work.
>
> Dim X
> 'Tried X = Eval(strRoutine & " (,true)") but got "The expression you
> entered contains invalid syntax" 'Next tried X = Eval(strRoutine & "
> (Restarted:=True)") but got "Microsoft Access cannot find the name
> 'Restarted' you entered in the expression. 'It seems arguments have to
> be passed all or nothing?
> I can do one of these, but it changes what I have to do
> inside my
> function:
> X = Eval(strRoutine & " ()")
> or
> X = Eval(strRoutine & " (False,True)")
>
> Of course, the arguments can be anything acceptable as parameters -
> e.g., I don't have to pass "False" for the first argument, I can pass
> anything that a variant can hold, since the parameter is declared as a
> variant... but I do have to pass either no arguments or all arguments
> in order. Which means I can no longer test IsMissing(Arg1) inside the
> function.
>
> I keep thinking that I am missing something elemental here.
> Thanks for those following and thinking about this on my behalf.
>
> Function DropIndexes(Optional T, Optional Restarted)
> '...Blah Blah
> End Function
>
> -----Original Message-----
> From: Bill Benson [mailto:bensonforums at gmail.com]
> Sent: Saturday, April 12, 2014 8:48 PM
> To: 'Access Developers discussion and problem solving'
> Subject: Application.Run not passing my arguments declared optionally
>
> I want some code which calls a dynamically named function and has a
> dynamically listed number of arguments to do this upon re-open of a
> database. So what I did was set the default form of my database to
> this invisible form. In that form, on load, I check a record in a
> table which should indicate the function or sub I want to call. So far
> I have tested this only with one routine, and while I can call that
> routine, I cannot seem to get the arguments to take hold. Basically, I
> get that they are missing, regardless how I have tried to structure
> the function call. A simple example:
>
> Private Sub Form_Load()
> Dim strRoutine As String
> strRoutine = Nz(DLookup("Function", "Tbl2"), "")
> If strRoutine <> "" Then
> 'Suppose Function had value 'DropIndexes'
> Debug.Print Application.Run(strRoutine, , True)
> End If
>
>
> Function DropIndexes(Optional T, Optional Restarted)
> Dim D As DAO.Database
> Dim i As Long
> 'Tried to pass nothing for T and True for Restarted
> Debug.print Ismissing(Restarted)
>
> '
> 'Result:
> 'True
>
>
> Based on this result I cannot even begin to explore further what I
> might do if the arguments are different, listed in different order, or
> whatever, for a different dynamically named routine.
>
> Thanks if anyone can help me get the arguments to take hold.
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>