Results 1 to 39 of 39

Thread: [ RESOLVED ]...Unloading Forms...

  1. #1

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up [ RESOLVED ]...Unloading Forms...

    VB Code:
    1. Private Sub cmdBack_Click()
    2.     frmMain.Show
    3.    
    4.     Dim frm As Form
    5.     For Each frm In Forms
    6.         If frm <> frmMain Then
    7.             Unload frm
    8.             Set frm = Nothing
    9.         End If
    10.     Next frm
    11. End Sub

    What is wrong with this code...???

    Gives compile error: Type mismatch

    Hope some one can fix it...!!!

    Cheers...
    Last edited by wrack; Jul 15th, 2002 at 09:18 PM.

  2. #2
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    which line gives you the error? Try using Unload Me and not using the Set frm = Nothing and see if that works.
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  3. #3

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    This will help...

    VB Code:
    1. If frm <> frmMain Then

    It gives an error at frm in the line above...

    Cheers...

  4. #4
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    D'Oh!! You need to use this:

    VB Code:
    1. If frm.name <> "frmMain" Then
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  5. #5

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Arrow hmmmm....

    ThX Bill,

    that one is solved...

    another problem...

    It unloads the frmMain aswell...why...???

    VB Code:
    1. Private Sub cmdBack_Click()
    2.     frmMain.Show
    3.    
    4.     Dim frm As Form
    5.    
    6.     For Each frm In Forms
    7.         If frm.Name <> "frmMain" Then
    8.             Unload frm
    9.             Set frm = Nothing
    10.         End If
    11.     Next frm
    12. End Sub

    Cheers...

  6. #6
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    Hey,

    I just tested your code in my app, and it works perfectly, it closes all the windows i have open, except for frmMain. The only reason i can think of for you main form closing as well is that it isn't call frmMain. When you do the name comparison it is case sensitive. Check you main form name and make sure its the same as the name in the if statement.
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  7. #7

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up hmmmm....

    thats right bill,

    Your computer does the right thing and that code was working when i left office on friday night and when i come today, magic of microsoft...it doesn't work...

    I am dead sure that its called frmMain and the case i have used is right but can't figure it out whats going on...

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Not sure on this but you may want to try:
    VB Code:
    1. If frm.Name Is Not frmMain Then

  9. #9

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs down hmmmm....

    ThX Edneeis,

    but it gives a type mismatch error at 'Not' from the code u posted...

    Cheers...

  10. #10
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Try this:

    Give frmMain a special tag (like 25360) and use:

    VB Code:
    1. Private Sub cmdBack_Click()
    2.     frmMain.Show
    3.    
    4.     Dim frm As Form
    5.    
    6.     For Each frm In Forms
    7.         If frm.tag <> 25360 Then
    8.             Unload frm
    9.             Set frm = Nothing
    10.         End If
    11.     Next frm
    12. End Sub


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  11. #11
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    Yeah Wrack. I had a similar prob the other day. I had a major error that appeared in my app. Spent 2 days looking for a cause and couldn't find one. Then the other day i tried to show someone the problem and it didn't occur. Hasn't reappeared either. I hadn't done a thing to the code but. . . .

    But thats Microsoft products
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  12. #12
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    I have problems like that all the time. All of a sudden, my subclassed program would crash for no reason and all of a sudden, without pressing a key, the program worked (on my next windows reboot). That is the quality you get with M$ products...in addition to poor $90-per-call technical support and a poor bug response system (I sent three bugs eports - two were completely lost and one gave back a irrelevant result).


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  13. #13

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up ThankX

    Microbasic, Bill for your prompt response but its working now and I haven't done anything to it...

    I will post this again if the problem reappears...

    Cheers...

  14. #14

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs down mesa back...

    the problem is back again...how do i get rid of it...

    I am trying to work it out since 4 hours and its pain in a*** and my boss is really pissed of because of no constructive work...

    Cheers...

  15. #15
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    VB Code:
    1. frmmain.Show
    2.    
    3.     Dim frm As Form
    4.    
    5.     For Each frm In Forms
    6.         If frm.Name <> frmmain.Name Then 'changed frmMain to frmMain.Name, because you are comparing NAMEs, not FORMS
    7.             Unload frm
    8.             Set frm = Nothing
    9.         End If
    10.     Next frm
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  16. #16

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs down noop...

    same thing...it unloads all form including frmMain...

    any more ideas...

    Cheers...

  17. #17
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    i just tried it. it works. check all your form unloads and see if you are doing anything bad there.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  18. #18

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up it was working b4...

    ThX buggy but it was working completely allright b4 i went to lunch and I came back and now its not working...

    I am sure that I am not doing anything bad...

    Cheers...

  19. #19
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    this works for me, so run it and see if it works for you.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  20. #20
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Wrack, show us your whole code. Everything that is in that Sub.

    If that is everything then i dont know what the deal is becasue i just tried and it works fine.

    Also, look in your other forms Unload_Events...Is it possible you are closing the FrmMain in one of those events?
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  21. #21

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Wink hmmm..

    Your code works fine and I copied my code to your project and it works fine...

    But why doesn't it work on my project...I have got exactly the same thing but I can't understand what the h*** it doesn't work on my prokect...

    hope someone has a same problem and they can help me...

  22. #22
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    post all your unload subs from all your forms. did you even check?
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  23. #23

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up Here it goes...

    VB Code:
    1. ' This same code works in other FORMS but not this one
    2.  
    3. Private Sub cmdBack_Click()
    4.     frmMain.Show
    5.  
    6.     Dim frm As Form
    7.  
    8.     For Each frm In Forms
    9.         If frm.Name <> "frmMain" Then
    10.             Unload frm
    11.             Set frm = Nothing
    12.         End If
    13.     Next frm
    14. End Sub
    15.  
    16. Private Sub cmdSupport_Click()
    17.     Call JumpBetweenForms
    18.     Call frmMain.cmdSupport_Click
    19. End Sub
    20.  
    21. Private Sub JumpBetweenForms()
    22.     Dim frm As Form
    23.    
    24.     For Each frm In Forms
    25.         If frm.Name <> "frmMain" Then
    26.             Unload frm
    27.             Set frm = Nothing
    28.         End If
    29.     Next frm
    30. End Sub
    31.  
    32. 'This is frmMain.cmdSupport_Click event
    33.  
    34. Public Sub cmdSupport_Click()
    35.     On Error GoTo ErrorHandler
    36.    
    37.     Set cnnMain = New ADODB.Connection
    38.     cnnMain.CursorLocation = adUseClient
    39.    
    40.     Call modError.ADO_Error
    41.    
    42.     Screen.MousePointer = vbHourglass
    43.     frmSupport.Show
    44.     Me.Hide
    45.     Screen.MousePointer = vbNormal
    46.    
    47. ErrorHandler:
    48.     If Err.Number = -2147467259 Or Err.Number = -2147217865 Then
    49.         Dim intYesNo As Integer
    50.         intYesNo = MsgBox("System could not find DATABASE or DATABASE format is incorrect. Please locate it and press Apply Changes button. Would you like to locate it.", vbCritical + vbYesNo, "Austrak Licencing Management System")
    51.         If intYesNo = 6 Then
    52.             Me.Hide
    53.             frmAdmin.Show
    54.         Else
    55.             End
    56.         End If
    57.     End If
    58. End Sub

  24. #24
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    i thought you said you changed

    If frm.Name <> "frmMain" Then

    to

    If frm.Name <> frmMain.Name Then




    how many forms do you have? post all your unload code like i said.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  25. #25

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up it doesn't matter...

    I tries that way aswell and in all other forms its just "frmMain" not frmMain.Name

    I thought that doesn't make any difference as it works in all other forms...

    Cheers...

  26. #26
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    so did you check your ALL unload code? you never actually said you did you just assumed it would be ok. make sure you don't have any frmMain.Unload or something that would unload all forms.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  27. #27

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up I checked all...

    I checked everywhere and couldn't find anything which unloads the frmMain...

    Cheers...

  28. #28
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    I have had similar, though not identical, problems. Try using
    VB Code:
    1. frmmain.Show
    2.     Dim frm As Form
    3.     For Each frm In Forms
    4.         If frm.Name <> frmmain.Name Then
    5.             'Unload frm --> Do not use this
    6.             Set frm = Nothing
    7.         End If
    8.     Next frm

    See if that sort of helps.

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  29. #29
    Fanatic Member Slaine's Avatar
    Join Date
    Jul 2002
    Posts
    641
    Can you not step through the execution (F8) and see at what point it unloads frmMain?
    Martin J Wallace (Slaine)

  30. #30
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    You sure it is unloaded and not just hidden? I see a few .Hide 's in there... also a bit of spaghetti coding eg frmMain.cmdSupport_Click.

    Do a global search for Unload statements or Nothing and Rem them all out and then add back one at a time. Maybe u are unloading frm Main in the unload event of another form
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  31. #31
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Angry Arrr...Sod it! Goodbye Mr Hodgeheg...*sob*

    Use:
    VB Code:
    1. If Not frm Is frmMain Then
    That will do the trick as it's checking to see if frm is the same object as frmMain...simple. Try it, it will work...

    Woka

  32. #32
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Angry Arrr...Sod it! Goodbye Mr Hodgeheg...*sob*

    Use:
    VB Code:
    1. If Not frm Is frmMain Then
    That will do the trick as it's checking to see if frm is the same object as frmMain...simple. Try it, it will work...

    Woka

  33. #33

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up hmmmm....

    Thank you very much for your help Slaine...

    I step through it and found that while unloading all forms except frmMain, say for example I am in frmClient then the Form_Unload event of frmClient had a code to unload all forms and so when it was trying to unlaod all forms except frmMain it was invoking frmClient's Unload event and which was ultimately the cause of trouble...

    Appreciate all of your reply and thankx again to make me solve that problem in 1 day...

    Cheers...

  34. #34
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    ........ you know i DID tell you 3 times to check ALL your form's unload subs....
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  35. #35

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up ThankX

    BUGGY,

    But I was looking for a code like this...

    VB Code:
    1. Unload frmMain

    and I search through whole code but can't find it obvously because the code was like this...

    VB Code:
    1. Dim frm As Form
    2.    
    3.     For Each frm In Forms
    4.         Unload frm
    5.         Set frm = Nothing
    6.     Next frm

    I learned a huge lesson today...listen to BUGGY......

    Cheers...

  36. #36
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Listen to buggy? If you read the thread you will see that i was the one that suggested you look at all the unload subs of the other forms.


    But that's ok, I'm used to doing all the work and getting no credit
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  37. #37
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by Arc
    Listen to buggy? If you read the thread you will see that i was the one that suggested you look at all the unload subs of the other forms.


    But that's ok, I'm used to doing all the work and getting no credit
    look 3 replies above yourse
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  38. #38

    Thread Starter
    ^:^...ANGEL...^:^ wrack's Avatar
    Join Date
    Mar 2002
    Location
    Melbourne, AUSTRALIA
    Posts
    2,695

    Thumbs up hmmmm....

    if u see the reply...I am kicking...

    but THX to all...

  39. #39
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Originally posted by BuggyProgrammer


    look 3 replies above yourse

    Doh! i'll be damned. You beat me too it hehe. Good Job
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


Posting Permissions

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



Click Here to Expand Forum to Full Width