Results 1 to 7 of 7

Thread: Excel VBA guru please

  1. #1
    Join Date
    Feb 2007
    Location
    Brisbane
    Posts
    4,497
    Total Downloaded
    0

    Excel VBA guru please

    Silly problem which I can't figure out.

    I have a protected spreadsheet. The user can press a button to open a form (vb Modeless) that allows the user to copy and paste rows. I've placed a help button on the form which opens another "help" form.

    Help button code:
    Private Sub cbHelp_Click()
    Unload fmCopy_Rows
    fmHelp.Show
    End Sub


    The "Help" form contains text and a close button:
    Private Sub cbClose_Click()
    Unload fmHelp
    fmCopy_Rows.Show vbModeless
    End Sub


    My problem is that I can't get the original fmCopy_Rows form to reappear. What am I missing?

    Cheers.

  2. #2
    Join Date
    Feb 2007
    Location
    Perth
    Posts
    3,918
    Total Downloaded
    0
    Once you have 'unloaded' an object (ie fmCopy_Rows) you have completely removed it from memory. You just can't get it back by 'showing' it. Check out the 'load' statement documentation.

    I think that might be your problem.
    2024 RRS on the road
    2011 D4 3.0 in the drive way
    1999 D2 V8, in heaven
    1984 RRC, in hell

  3. #3
    Join Date
    Feb 2007
    Location
    Brisbane
    Posts
    4,497
    Total Downloaded
    0
    Thank Ferret. Made some mods but it still doesn't work.

    In my module I "show vbModeless" the Copy form which loads it.

    fmCopy_Rows.Show vbModeless

    In the Copy form in the Help_Click code I hide the Copy form and Show (load) the Help form:
    Private Sub cbHelp_Click()
    fmCopy_Rows.Hide
    fmHelp.Show
    End Sub


    In the Help form in the Close_Click code I unload the Help form and go back to module code.
    Private Sub cbClose_Click()
    Unload fmHelp
    Copy_Rows 'Calls the original sub
    End Sub


    This seems to work ok when I step through the code (F8) but not when I run it.

  4. #4
    Join Date
    Feb 2007
    Location
    Brisbane
    Posts
    4,497
    Total Downloaded
    0
    I closed Excel and restarted. The code works perfectly now.

    Thanks Ferret.

  5. #5
    Join Date
    Feb 2007
    Location
    Perth
    Posts
    3,918
    Total Downloaded
    0
    Just a comment on what you are doing and maybe it does not matter to your particular application if it is relatively small but if you are hiding 'frmCopy_Row' then later calling 'Copy_Rows'(which I assume creates, load the object 'frmCopy_Row' into memory then shows it) then you are creating multiple instances of that object.

    ie you have 1 instance of frmCopy_Row in memory but hidden from view then you create another instance of it when you call 'Copy_Rows' again just before returning from cbClose_Click. You now have 2 instances of frmCopy_Row one of which is occupying memory but can no longer be accessed.

    Repeat this several times and you have the makings of a 'memory leak'.
    2024 RRS on the road
    2011 D4 3.0 in the drive way
    1999 D2 V8, in heaven
    1984 RRC, in hell

  6. #6
    Join Date
    Feb 2007
    Location
    Brisbane
    Posts
    4,497
    Total Downloaded
    0
    Thanks Ferret, but the Copy_Rows code only Shows the form. My understanding of Show is that if the form is not already loaded, Show will load it the first time.

    Cheers.

  7. #7
    Join Date
    Feb 2007
    Location
    Perth
    Posts
    3,918
    Total Downloaded
    0
    Yes, you are right about 'Show' - from the VBA documentation "If the specified object isn't loaded when the Show method is invoked, Visual Basic automatically loads it."

    But if this is correct then why does your original code not work? And my statement "Once you have 'unloaded' an object (ie fmCopy_Rows) you have completely removed it from memory. You just can't get it back by 'showing' it." implying you must load it after unloading it can't be right.

    Strange.
    2024 RRS on the road
    2011 D4 3.0 in the drive way
    1999 D2 V8, in heaven
    1984 RRC, in hell

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search AULRO.com ONLY!
Search All the Web!