Resume a command

coolmision
12-29-2004, 09:23 AM
hello,

I have a small issue when I'm trying to realize smthg like this:



TEST:
If MsgBox("Open a window?", vbYesNo + vbQuestion, "Question") = vbYes Then
frmtest.Show
Else
frmtest.show.text = "bla"

TEST2:
If MsgBox("Do you want to edit the value?", vbYesNo + vbQuestion, "Question") = vbYes Then
frmtest2.Show

.....



Now, my problem is that as soon as a user clicks on yes in the msgbox, a new form will appear and he will enter a form manually, then press a button. What I want to know now is, if it is possible to tell the program to resume at TEST2: when clicking on the button in another form? (as in resuming that code)

Thanks in advance

~cm

robertg
12-29-2004, 09:28 AM
Instead of having all the code in one routine, separate them into Public Subs on your form. Then, from the second form, you can call whatever routine you want the user to go through next.

coolmision
12-29-2004, 09:35 AM
So, should I put the code into Private Subs? Could I put them into a module and then call them seperately so I dont have to place them in every form?

robertg
12-29-2004, 09:36 AM
Regardless of whether they are on a form, or in a module, you would need to make them Public, rather than Private, if they were to be called from anywhere in your project, other than the form they are on. Probably a module would make more sense, yes.

coolmision
12-29-2004, 09:37 AM
I'm kinda new to visual basic ;) Thanks for the quick help, I'll tell you if it works as soon as possible. Thanks again!

eXeption
12-29-2004, 09:41 AM
First up all, using Labels and GoTo is considered as a bad practice in coding. Try to avoid it by reorganising your code.
Anyway,
No direct methods, I think, Try setting a public flag in the form you want to jump, and when the form shows check the flag and jump to a suitable position.

crabby
12-29-2004, 10:13 AM
well or you load that second form modal try

Private Sub Command1_Click()
Load Form2
Form2.Show vbModal
MsgBox "second form is now closed"
End Sub

HardCode
12-29-2004, 10:41 AM
After the .Show method, the rest of the code will still execute. Showing a form in a sub does not break execution of the rest of the code.

Oh, missed that vbModal :)

crabby
12-29-2004, 10:48 AM
Well it does on my machine. If I do the following I get the "did load the form" just after form2 is closed :confused:

Private Sub Command1_Click()
Load Form2
Form2.Show vbModal
Debug.Print "did load the form"
End Sub

eXeption
12-29-2004, 11:58 PM
morsnowski's code worked with me too!

Verphix
12-30-2004, 01:59 AM
showing a form modally does stop the execution of code on the line it was called from. When the modal form is closed, only then the code continues.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum