form Control auto updated from global variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • superspie
    New Member
    • Feb 2008
    • 3

    form Control auto updated from global variable

    Is it possible to cause a contents of a variable defined in a Module as public, to be retrieved by a control(textbox ) in the trailer of a bound single view Form.
    Where desired data is not associated with the Table. bound to the Form
    The variable's content is an application calculation.

    Environment:
    Windows Vista Ultimate, Access 2007

    object: Module1
    public varname as double

    object: myform
    Trailer section
    textbox: display

    failed attempt using :

    textbox: Display
    control source of: =Module1.varnam e

    I realize I could programatically do this off some Event, I just looking for another way

    --------------------------------------------------------------------------------
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Originally posted by superspie
    Is it possible to cause a contents of a variable defined in a Module as public, to be retrieved by a control(textbox ) in the trailer of a bound single view Form.
    Where desired data is not associated with the Table. bound to the Form
    The variable's content is an application calculation.

    Environment:
    Windows Vista Ultimate, Access 2007

    object: Module1
    public varname as double

    object: myform
    Trailer section
    textbox: display

    failed attempt using :

    textbox: Display
    control source of: =Module1.varnam e

    I realize I could programatically do this off some Event, I just looking for another way

    --------------------------------------------------------------------------------
    Hi Superspie. One way to get the value of a public (global) variable into a control is to write a public function to return its value and use a call to this function in the rowsource property.
    [CODE=VB] Public Function ReturnGlobal() as Double
    ReturnGlobal = Varname
    End Function
    [/CODE]
    You can then refer to this function in the rowsource property of your control (entering =ReturnGlobal() as the rowsource).

    -Stewart

    Comment

    • superspie
      New Member
      • Feb 2008
      • 3

      #3
      Thank you for the suggestion, however it yeilded only partial success. It appears that changes to a variable are not reflected in the control until a form refresh is done.

      Side note: initial attemps using the function solution were unsuccessful, there appeared to be residual flags on the control which still caused the #name error to occur, until I deleted the control and created a new one.

      I also tried to generalize the function also failed:

      Public Function Rtnvar(varname) as variant
      Rtnvar=varname
      End Function

      The above function would work in the debug Immeadiate window or in code, but not as Rowsource.

      Comment

      • Stewart Ross
        Recognized Expert Moderator Specialist
        • Feb 2008
        • 2545

        #4
        Originally posted by superspie
        Thank you for the suggestion, however it yeilded only partial success. It appears that changes to a variable are not reflected in the control until a form refresh is done...
        Hi Superspie. The refresh issue relates to the control on the form, not the public variable, and is one that crops up frequently when using unbound controls. Access updates bound vaues when these change, but unbound values often have to be user-refreshed.

        To refresh the value of the control alone - without refreshing the form - you can use the Requery method of the control itself. This can be done within the form code module using

        Me.[controlname].requery

        or from another code module by explicitly referring to the control

        Forms(formname) .Controls(contr olname).Requery

        -Stewart

        Comment

        Working...