Results 1 to 6 of 6
  1. #1
    argsemapp is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    18

    Getting variables from one function to another in VBA


    I have a form with a couple of events scripted in VBA (an AfterUpdate on a combobox, another OnClick on a button). Basically I want to use a string variable from the AfterUpdate code, in the OnClick section of the code. How do I do this?

    This string will be passed with OpenArgs to a report, if that makes a difference.

  2. #2
    argsemapp is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    18
    Actually dealing with this by moving the code from my AfterUpdate to my OnClick, but I would still like to hear how people would handle this kind of thing

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Options:

    1. Global or Public declared variable - variable declared in module header

    2. populate an unbound textbox on form - can be not visible

    3. TempVars - I've never used them

    4. custom collection - never done this either
    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.

  4. #4
    argsemapp is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    18
    Instead of passing the entire recordset I just passed the query for the recordset to the report. This seems to be okay for now but I can see myself having trouble bc this report will require multiple inputs from my form eventually...

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    1. parameterized query using LIKE operator with wildcard, review:
    http://datapigtechnologies.com/flash...earchform.html
    http://datapigtechnologies.com/flash...tomfilter.html
    http://datapigtechnologies.com/flash...mtoreport.html

    2. VBA code to construct criteria string and set the form Filter and FilterOn properties, review: http://allenbrowne.com/ser-62.html
    Or use WHERE CONDITION argument
    DoCmd.OpenReport "reportname", , , strWHERE
    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.

  6. #6
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    TempVars is a very good option, for reaosnable numbers of parameters.

    Demo module was posted here https://www.accessforums.net/code-re...ars-36353.html

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

Similar Threads

  1. Three variables for Criteria
    By lugnutmonkey in forum Queries
    Replies: 1
    Last Post: 01-30-2013, 11:52 AM
  2. VBA variables in SQL
    By compooper in forum Programming
    Replies: 3
    Last Post: 07-06-2011, 11:04 AM
  3. VBA in variables
    By smikkelsen in forum Access
    Replies: 3
    Last Post: 11-12-2010, 03:14 PM
  4. Eval function with variables
    By tuna in forum Programming
    Replies: 3
    Last Post: 05-14-2010, 06:02 PM
  5. sql in vb variables
    By emilylu3 in forum Programming
    Replies: 3
    Last Post: 03-04-2006, 01:26 PM

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