Thanks Dirk, Your suggestion worked very well. I did change vbMethod to vbGet Thanks again. Lee Wrenn
"Dirk Goldgar" <dg[ at ]NOdataSPAMgnostics.com> wrote in message news:e2qIZW$4GHA.3512[ at ]TK2MSFTNGP04.phx.gbl...
[Quoted Text] > "Lee Wrenn" <noemail[ at ]att.net> wrote in message > news:OzBDsM$4GHA.3512[ at ]TK2MSFTNGP04.phx.gbl >> I am trying to use a function to instantiate an instance of a class >> and return the value from the method specified as a parameter of the >> function. >> >> I have tried a couple of ways and used debug.print to get the values >> of the different expressions at execution and have indicated the >> return values in comments in the code. >> >> I am using the function as the criteria in a query in the following >> format: >> >> =getSwitch("Project") >> >> Project is a Get property in the class which looks up the project >> number in a table. >> When I specify objSwitch.Project in a debug.print statement the proper >> project number is returned which says it is being returned from the >> class module. >> >> I have indicated the error messages I received after the offending >> line where execution stops. >> I left one block of commented out alternate code that I tried. >> >> Any help would be appreciated. >> >> Lee Wrenn >> ________________________________________________________________ >> >> Public Function getSwitch(MethodName As String) As Variant >> Dim strCmd As String >> >> Dim objSwitch As clsSwitch >> Set objSwitch = New clsSwitch >> >> 'Debug.Print objSwitch.Project >> ''Hardcoded line above returns correct project number so get >> statement in class is working >> >> 'Try Eval on both sides of expression >> strCmd = "getSwitch = objSwitch." & MethodName >> Debug.Print strCmd >> 'Returns getSwitch = objSwitch.Project >> Eval (strCmd) >> 'generates error 2482 cant find 'getSwitch' >> >> ''Tried Eval on just the right side of expression >> ' strCmd = "objSwitch." & MethodName >> ' Debug.Print strCmd >> ' 'Returns objSwitch.Project >> ' getSwitch = Eval(strCmd) >> ' 'generates error 2482 cant find 'objSwitch' >> >> Set objSwitch = Nothing >> >> End Function > > Since you need to refer to the instance of the class object, I don't > think you can use Eval. However, if you're using Access 2002 or later > (and maybe A2K), you should be able to use CallByName: > > getSwitch = CallByName(objSwitch, MethodName, vbMethod) > > -- > Dirk Goldgar, MS Access MVP > www.datagnostics.com > > (please reply to the newsgroup) > >
|