none
Public variable losses the value RRS feed

  • Question

  • HI 

    I am new to programming, so excuse me if my question is naive.

    I declared a public variable and assigned it a value in a sub procedure. 

    When I try to access the same variable in another sub procedure, to get the value assigned in the first procedure the variable retains its value (as assigned by the first procedure) when I am run the second procedure first time. 

    But when I run the second procedure again the public variable's value is automatically set to 0. 

    Could some help me in understanding this?

    Thanks!

    Tushar

    Tuesday, May 20, 2014 4:03 PM

All replies

  • Is this variable declared Public in a Form module? If so the variable is not exactly for Public access. If you are accessing the variable inside the same Form, check if any other code resets the variable.

    Happy to help ! When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answered

    Tuesday, May 20, 2014 4:14 PM
  • You want a project-level public variable.  See this for all details.

    http://www.ozgrid.com/VBA/variable-scope-lifetime.htm


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Thursday, May 22, 2014 2:31 PM