Results 1 to 4 of 4
  1. #1
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    using Public variable (XP/2K)

    I have a running count of what is happening in a code loop on a form. The counts are kept as a public variable in the module of the form. Could I use those variables as the control source for a text box on a report that would open when the code ends, but the form is till open? If yes, how would I reference them?
    I know there seem to be easier ways to do this, but the report would need six subreports, and also I need the data as the code runs.
    Thanks

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: using Public variable (XP/2K)

    A control on report will not be able to reference a variable, Public or Private, in a form module. Assign the value of the variable to a (hidden) textbox on form. The report can then reference this value using syntax like this:

    Forms![Form1]![Textbox1]

    Where Form1 is form with the variable, and Textbox1 is the textbox used to store value of variable. Whatever code is used to set value of variable can be used to update value of textbox at same time (or just use textbox if practical).

    HTH

  3. #3
    5 Star Lounger
    Join Date
    Nov 2001
    Location
    Jerusalem, Israel
    Posts
    708
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: using Public variable (XP/2K)

    I ended up using a different idea . I created a blank report with labels that are one blank space, I then open it, from the code on the form that has the variables, in design view and change the caption of those labels based on the variables , and then reopen the report in preview and print mode. That also works.
    Thanks

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: using Public variable (XP/2K)

    To refer to a variable in a form or a report, just use a function.
    Public Function MyVariable
    MyVariable = MyGlobalVariable
    End Function

    In the control source of your form or report use : =MyVariable()
    Francois

Posting Permissions

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