Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Dec 2000
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Vaporized variables (A2K)

    I am having a problem with local variables losing their value.

    Here is a simplified code flow of the problem area.

    ---- Start code

    FormA
    =====

    Declarations

    Private strName as String
    Public blnFlag as Boolean

    Private FormA_Load()
    blnFlag = False
    End Sub

    Private Sub cmdCallFormB_Click()
    strName = "Hold value"
    debug.print "CallFormB: "; strName; blnFlag
    Docmd.Openform "FormB"
    End Sub

    Private Sub FormA_Activate()
    debug.print "FormA Activate: "; strName; blnFlag
    End Sub


    FormB
    =====

    Private Sub cmdButton_Click()
    Form_FormA.blnFlag = True
    End Sub

    Private Sub cmdExit_Click()
    Docmd.Close
    End SUb

    --- End code

    Here's what I'll see in the Immediate Window:

    FormA Activate: False
    CallFormB: Hold value False
    FormA Activate: True

    This is what's happening:

    FormA opens
    FormA saves a private value
    FormA opens FormB
    FormB changes a public boolean in FormA
    FormB closes
    When FormA activates again, the saved private value has been nulled.

    There is something more complicated going on than what I have here, because the simple code above works fine by itself. I don't know how to post my actual code because it involves subforms and ADO recordsets.

    The actual values I am saving are the keys to a record. What I want to do is display a detailed record form after it has been selected from a subform list in a datasheet view on FormA. Then if the 'Delete' button on FormB is clicked, FormA will delete that record.

    If I put a watch on the variables that are being changed with "break on change", even the watch window doesn't see them get erased.

    I have been at this one for two days now. Any ideas or suggestions will be gratefully received.

    TIA
    Donald

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Vaporized variables (A2K)

    Change the initialization of the public variable to the Open event of FormA instead of the Load event. Open only happens once, so it is less likely to step on itself. Then change the command in form B to this:

    Forms!FormA.blnFlag = True

    The public variable you created functions as a public property for the FormA class, so you have to reference it properly in order to set and retrieve it.
    Charlotte

  3. #3
    2 Star Lounger
    Join Date
    Dec 2000
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Vaporized variables (A2K)

    Well Charlotte, it appears that once again you have pulled my sorry butt out of the fire - - or kept me from going postal.

    I believe that changing

    Form_FormA.blnFlag

    to

    Forms!FormA.blnFlag

    did the trick.

    Now, can you tell me the secret search term to find the article explaining this terminology. I'm pretty sure that I have used the Form_frm type reference before and that it appears to work up to now. I guess I better go search my code and make some changes.

    The thing that confuses me is that if you go into the object browser it shows the Form_frm format and if I type it in the VBA window when you hit the '.' you are offered the variable and it all compiles. Why is that?

    Thanks
    Donald

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Vaporized variables (A2K)

    I think it's really a matter of what you're doing. When you use the Form_formname syntax, you're referring to the form's class module, where you can call public methods, etc. When you use the Form.property syntax, you're referring directly to the form's *property* (in this case a public variable) which, since it's public, can be changed from outside.
    Charlotte

Posting Permissions

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