[ Problem Loading A Form from cmdExit ]

FantasiaDown
09-05-2003, 10:31 AM
I'm having a problem with a small bit of code that i'm not sure how to finish.

In a application i'm coding that involves the user to Exit a data entry screen (being frmAdd) and return to the Main screen (being frmMain), I
am having problems unloading this Addfrm and then having the Mainfrm show again.The rest of the code works fine - once the user is asked if they would like to exit the entry and they click on the yes btn, the application ends.instead however, i would like the user to just be returned to the main screen.

here is what i have for the code for the cmdExit button for the
Addfrm.

Private Sub cmdExit_Click()
Const conbtns As Integer = vbYesNo + vbExclamation + vbDefaultButton1 + vbApplicationModal
Dim intuserresponse As Integer
intuserresponse = MsgBox("Are You sure you want to exit this entry?", conbtns, "Personal Phone Book")
If intuserresponse = vbYes Then
Unload frmAdd
Load frmMain
End
End If



when i test the application with this code, nothing drastically horrible happens like i fist anticipated.the application just ends when i would like the user to be returned to the main screen. what am i not doing correctly here ?


- as always, all comments and suggestions are gratefully welcome !

thanks for the help.

SnakeChomp
09-05-2003, 10:38 AM
You can try doing this instead of unloading frmAdd before loading frmMain:
1. Hide frmAdd.
2. Load and Show frmMain.
3. Unload frmAdd.

If you unload frmAdd before showing frmMain, frmAdd never gets to the code that shows frmMain because it will be removed from memory as a result of the Unload call.

FantasiaDown
09-05-2003, 10:45 AM
I believe i've already tried allof that and still i seem not to be getting the result i'm looking for. I'll have to give it another try and see what happens.

thanks..

You can try doing this instead of unloading frmAdd before loading frmMain:
1. Hide frmAdd.
2. Load and Show frmMain.
3. Unload frmAdd.

If you unload frmAdd before showing frmMain, frmAdd never gets to the code that shows frmMain because it will be removed from memory as a result of the Unload call.

Squishy
09-05-2003, 10:15 PM
Private Sub cmdExit_Click()
Const conbtns As Integer = vbYesNo + vbExclamation + vbDefaultButton1 + vbApplicationModal
Dim intuserresponse As Integer
intuserresponse = MsgBox("Are You sure you want to exit this entry?", conbtns, "Personal Phone Book")
If intuserresponse = vbYes Then
Unload frmAdd
Load frmMain
End ' <-- why is this here? This will terminate your program.
' Also, using End will terminate your program
' prematurely without unloading it from memory.
' Because of that, it is better practice to loop through
' all the Forms and use Unload instead of just End.
End If

End Sub


Once you Unload a Form, its code will stop executing. Move "Load frmMain" before "Unload frmAdd", and get rid of End. Also, I think that once a form is loaded into memory, using Load again will not do anything. Try using frmMain.Show instead of Load frmMain.

FantasiaDown
09-08-2003, 07:49 AM
[ Hi again ]

I got the proper code working finally.
I had been meaning to reply for quite a while but things in my life have been crazily busy lately.anyway, thanks again for the suggestions with the code...everything so far is moving quite smoothly and to my liking.








Private Sub cmdExit_Click()
Const conbtns As Integer = vbYesNo + vbExclamation + vbDefaultButton1 + vbApplicationModal
Dim intuserresponse As Integer
intuserresponse = MsgBox("Are You sure you want to exit this entry?", conbtns, "Personal Phone Book")
If intuserresponse = vbYes Then
Unload frmAdd
Load frmMain
End ' <-- why is this here? This will terminate your program.
' Also, using End will terminate your program
' prematurely without unloading it from memory.
' Because of that, it is better practice to loop through
' all the Forms and use Unload instead of just End.
End If

End Sub


Once you Unload a Form, its code will stop executing. Move "Load frmMain" before "Unload frmAdd", and get rid of End. Also, I think that once a form is loaded into memory, using Load again will not do anything. Try using frmMain.Show instead of Load frmMain.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum