Results 1 to 10 of 10
  1. #1
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Vail, Colorado, USA
    Posts
    194
    Thanks
    36
    Thanked 0 Times in 0 Posts

    Question Passing Variables to use with Open Report Event

    I have a Form and Sub Form. Once data is entered it produces a report which I save as a PDf using Bullzip.

    On the master form the report name is complied from the Name of the customer the batch number and month and year of transaction. To use that name as the report name for my PDF I need to change the caption on the report that is called from the master form.

    I tried creating a Public Variable to carry the report name but for some reason when I open the report the variable is not there.

    Worked around this by creating a control on the master form the value of which is called on the open form event and set as the caption. Works but very clumsy.

    Any suggestions as to how I can just maintain the variable until the report is called.

    thanks

    Peter

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    you could pass the variable in the OpenArgs I believe

  3. The Following User Says Thank You to patt For This Useful Post:

    mitchbvi (2013-06-29)

  4. #3
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Vail, Colorado, USA
    Posts
    194
    Thanks
    36
    Thanked 0 Times in 0 Posts
    I will try that but as i loose the variable just setting the focus for the subform not sure how to retain it through the opening of the report.

    Thanks

    Peter

  5. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,623
    Thanks
    3
    Thanked 60 Times in 60 Posts
    Rather than declaring it as Public, try Global. That should be available in any form or report for the duration of the Access session. You do however need to be careful if more than one user has the database open at the same time. That can be solved by giving each user their own copy of the front-end, assuming that you have a split structure that uses linked tables.
    Wendell

  6. The Following User Says Thank You to WendellB For This Useful Post:

    mitchbvi (2013-06-30)

  7. #5
    3 Star Lounger HiTechCoach's Avatar
    Join Date
    Sep 2011
    Location
    Oklahoma City, OK
    Posts
    200
    Thanks
    0
    Thanked 31 Times in 30 Posts
    Quote Originally Posted by mitchbvi View Post
    Worked around this by creating a control on the master form the value of which is called on the open form event and set as the caption. Works but very clumsy.
    Peter,

    Not sure why you think it is clumsy. That is very common practice by Access experts to use hidden text boxes on forma to hold global data. I still used is a lot in Access 2003 and older versions.

    One of the main advantages to using a control on a form is that it will retain the data if there is an error. Many errors will reset all global VBA variables to be empty. Compiling our Front end int a .mde/.accde and run it with Aces in Runtime mode will prevent the global VBA variables from resetting.

    Access 2007 and later TempVars collection:

    If you are using Access 2007 or later then use the new TempVars collection. One advantage to TempVars is that they can be used in queries.

    If you have Access 2003 or older I would recommend looking into using a Class.
    Last edited by HiTechCoach; 2013-06-29 at 13:56.
    Boyd Trimmell aka HiTechCoach (Access Information here)
    Microsoft MVP - Access Expert
    "If technology doesn't work for people, then it doesn't work."

  8. The Following User Says Thank You to HiTechCoach For This Useful Post:

    mitchbvi (2013-06-30)

  9. #6
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Vail, Colorado, USA
    Posts
    194
    Thanks
    36
    Thanked 0 Times in 0 Posts
    No luck the variable gets lost before I get to opening the report. thank you for the suggestion.
    Peter

  10. #7
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Vail, Colorado, USA
    Posts
    194
    Thanks
    36
    Thanked 0 Times in 0 Posts
    I am using 2003 probably should update but I use Windows in emulation mode on a Mac and careful about breaking something that works. I do not know how to use a class but will research. Thank you for responding.

    peter

  11. #8
    2 Star Lounger
    Join Date
    Apr 2003
    Location
    Vail, Colorado, USA
    Posts
    194
    Thanks
    36
    Thanked 0 Times in 0 Posts
    Thanks for that suggestion I had tried Global which did not make any difference is there a particular location within the project that Globals should be declared?

    Peter

  12. #9
    3 Star Lounger HiTechCoach's Avatar
    Join Date
    Sep 2011
    Location
    Oklahoma City, OK
    Posts
    200
    Thanks
    0
    Thanked 31 Times in 30 Posts
    Quote Originally Posted by mitchbvi View Post
    Thanks for that suggestion I had tried Global which did not make any difference is there a particular location within the project that Globals should be declared?

    Peter
    Peter,

    Where you declare a variable will determine the scope of where it can be used.

    If you want a variable to be available from any form and/or report then you need to declare the variable at teh top of a standard code module.

    Note: A form control is available from any other form and report. You do not have to worry about where to declare it like a variable

    Have you tried passing the value in the OpenArgs parameter?

    If you want to use a variable, I would suggested using a Class module.
    Last edited by HiTechCoach; 2013-06-30 at 15:13.
    Boyd Trimmell aka HiTechCoach (Access Information here)
    Microsoft MVP - Access Expert
    "If technology doesn't work for people, then it doesn't work."

  13. #10
    3 Star Lounger HiTechCoach's Avatar
    Join Date
    Sep 2011
    Location
    Oklahoma City, OK
    Posts
    200
    Thanks
    0
    Thanked 31 Times in 30 Posts
    Quote Originally Posted by mitchbvi View Post
    Thanks for that suggestion I had tried Global which did not make any difference is there a particular location within the project that Globals should be declared?

    Peter
    Sounds like you need to move the declaration to the top of a standard code module.
    Boyd Trimmell aka HiTechCoach (Access Information here)
    Microsoft MVP - Access Expert
    "If technology doesn't work for people, then it doesn't work."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •