Results 1 to 4 of 4
  1. #1
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    Use of Eval function to call VBA functions using string variable

    I have tried to use the following code


    [Code]
    Dim strProc As String
    Dim strParam As String
    Dim strTot As String
    Dim bReturn As Boolean




    strProc = "TestFuncCall"
    strParam = Chr(34) & "Hello John" & Chr(34)


    strTot = strObj & strProc & "(" & strParam & ")"
    Debug.Print strTot
    Debug.Print Eval(strTot) '**** Error occurs here '''can't find function TestFuncCall...


    TestFuncCall (strParam) '++++ This works, definition: TestFuncCall(strName as string)as Boolean


    [Code/]

    Am I missing something? Thanks for any help

  2. #2
    hapm is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    197
    How the TestFuncCall function is declared? Should be something like: Public Function TestFuncCall(strName As String) As Boolean. The important thing is that it should be public.

  3. #3
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124

    Using Eval fucntion to call a Public function

    Quote Originally Posted by hapm View Post
    How the TestFuncCall function is declared? Should be something like: Public Function TestFuncCall(strName As String) As Boolean. The important thing is that it should be public.

    I can't get the Eval("TestFuncCall("Hey John")) it gives me an error message whereas the VBA code calling the same function testFuncCall("hey John") worked. SO the question is why??

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    strObj is not declared or set in the procedure.

    It is possible to call procedures behind forms:
    Debug.Print Form_FormName.TestFuncCall(strParam)
    Debug.Print Forms("FormName").TestFuncCall(strParam)

    Cannot get the Eval function to resolve form object variable.

    Why do you need to refer to a function by variable? Why need to call function behind form?


    BTW, end CODE tag should be [/CODE].
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Trouble with string variable in custom vba function
    By CurrentUser in forum Programming
    Replies: 4
    Last Post: 01-10-2014, 09:13 PM
  2. Replies: 3
    Last Post: 05-28-2013, 12:53 PM
  3. Access - Eval function
    By dodo47 in forum Access
    Replies: 19
    Last Post: 02-11-2012, 02:02 AM
  4. String functions
    By posstrap in forum Access
    Replies: 1
    Last Post: 08-12-2011, 09:08 PM
  5. Eval function with variables
    By tuna in forum Programming
    Replies: 3
    Last Post: 05-14-2010, 06:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums