Results 1 to 5 of 5

Thread: static variable

  1. #1
    Join Date
    May 2002
    Posts
    395

    Unanswered: static variable

    I would like to store the value in a (static)variable so the textbox will retain the same value when next time the form opens up. The value was saved in the variable right before the form closed but it is not there when the form opens. Why??

    Public Sub Form_Close()
    Static eMonth As String

    eMonth = Me!txtEndingMonth
    'Debug.Print eMonth
    End Sub


    Public Sub Form_Open(Cancel As Integer)
    Static eMonth As String

    Me!txtEndingMonth = eMonth

    End Sub


    Thanks!

  2. #2
    Join Date
    Nov 2002
    Posts
    150

    Re: static variable

    Originally posted by alicejwz
    I would like to store the value in a (static)variable so the textbox will retain the same value when next time the form opens up. The value was saved in the variable right before the form closed but it is not there when the form opens. Why??

    Public Sub Form_Close()
    Static eMonth As String

    eMonth = Me!txtEndingMonth
    'Debug.Print eMonth
    End Sub


    Public Sub Form_Open(Cancel As Integer)
    Static eMonth As String

    Me!txtEndingMonth = eMonth

    End Sub


    Thanks!
    You need to make eMonth a global variable (you can do this by declaring it in a module: global eMonth As String

    Remove the variable declarations from Form_Open and Form_Close.

  3. #3
    Join Date
    Nov 2002
    Location
    Ohio
    Posts
    90
    Hi Alice,

    When a form is unloaded all variables and objects declared in the form are released.

    If the form is part of a MDI project, you could define the variable as "Public" in the MDI Form or "Global" in a module. The variable would be retained for the duration of the MDI project execution...but it would go away when the MDI project was unloaded.

    To have the value available every time the form is opened, you will have to save the value to a file, database table or put it in the Windows registry. You could then load the value when the form is opened.

    Good Luck,
    Bruce Baasch

  4. #4
    Join Date
    May 2002
    Posts
    395
    Originally posted by Bruce A. Baasch
    Hi Alice,

    When a form is unloaded all variables and objects declared in the form are released.

    If the form is part of a MDI project, you could define the variable as "Public" in the MDI Form or "Global" in a module. The variable would be retained for the duration of the MDI project execution...but it would go away when the MDI project was unloaded.

    To have the value available every time the form is opened, you will have to save the value to a file, database table or put it in the Windows registry. You could then load the value when the form is opened.

    Good Luck,
    Thank you so much for your help!
    Enjoy your holiday!

  5. #5
    Join Date
    May 2002
    Posts
    395

    Re: static variable

    Originally posted by FirstAndGoal4
    You need to make eMonth a global variable (you can do this by declaring it in a module: global eMonth As String

    Remove the variable declarations from Form_Open and Form_Close.
    Thanks for your reply.
    Happy Thanksgiving!

Posting Permissions

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