Results 1 to 2 of 2
  1. #1
    craig1988 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2014
    Posts
    82

    Use a variable value from a different function

    Hi

    I have got myself into a muddle



    I want to set a variable within a function. The variable is strOutput and is a string. I have this tested and it works fine.

    I have an onClick event that I want to use the variable above in. I am so confused??? The onClick Code goes as below...


    Code:
    Public Sub btnRequest_Click()  
        MsgBox strOutput, vbInformation, "Test"
    End Sub
    Obviously this is not all the above sub does but its just an idea of what I need to do.

    Have I got myself mixed up between public/private function/sub?
    I think I have to declare the variable in the second sub but I dont know how??

    Regards

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Either the function should return the string:

    MsgBox FunctionName(), vbInformation, "Test"

    Or the variable would have to be declared as public in a standard module

    Public strOutput As String
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. function help to append alphabets to variable?
    By akapag22 in forum Programming
    Replies: 1
    Last Post: 03-15-2015, 12:33 PM
  2. Public variable not updating for each function
    By Ruegen in forum Programming
    Replies: 3
    Last Post: 08-28-2014, 06:26 PM
  3. Trouble with string variable in custom vba function
    By CurrentUser in forum Programming
    Replies: 4
    Last Post: 01-10-2014, 09:13 PM
  4. Referencing a textbox using variable values from a function?
    By omahadivision in forum Programming
    Replies: 3
    Last Post: 12-20-2012, 09:23 AM
  5. pass a variable to the MsgBox function
    By 3dmgirl in forum Programming
    Replies: 2
    Last Post: 04-19-2007, 07:14 AM

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