Form Actions

  • Thread starter Thread starter Phil
  • Start date Start date
P

Phil

Hi,

I have 2 forms on the first form is a button which saves the current work
book, unloads the form and then opens the second form. The problem is when I
click the first button the form does not shut and the second one opens over
the top and when you click the button on the second form to shut it the whole
thing crash's can someone help, here is code I am using

Button One

Private Sub Finnish_Click()
ActiveWorkbook.Save
ActiveWorkbook.SaveAs Filename:="C:\Questionaire.xls"
Unload Me
UserForm3.Show
End Sub

Button Two

Private Sub UserForm_Click()

Unload Me
End Sub


Thanks
 
Hi Joel,

Thanks for the reply, I have tried what you suggested but am still getting
the same problem, any other thoughts??

Thanks
 
I thought this would work

Private Sub Finnish_Click()
ActiveWorkbook.Save
ActiveWorkbook.SaveAs Filename:="C:\Questionaire.xls"
Userform2.Hide
UserForm3.Show
End Sub

Button Two

Private Sub UserForm_Click()

msgbox("Put some code here to stop userform three from immediately shutting
down")
Userform3.Unload
End Sub
 
Create a new sub in a standard module that shows the second form:

Sub OpenSecondForm()
UserForm3.Show
End Sub

Back in Sub Finnish_Click replace:

UserForm3.Show

with

Application.OnTime Now, "OpenSecondForm"

--
Jim
| Hi Joel,
|
| Thanks for the reply, I have tried what you suggested but am still getting
| the same problem, any other thoughts??
|
| Thanks
|
|
| "Joel" wrote:
|
| > Hide the userform before opening the 2nd userform. You don't need the
unload.
| >
| > "Phil" wrote:
| >
| > > Hi,
| > >
| > > I have 2 forms on the first form is a button which saves the current
work
| > > book, unloads the form and then opens the second form. The problem is
when I
| > > click the first button the form does not shut and the second one opens
over
| > > the top and when you click the button on the second form to shut it
the whole
| > > thing crash's can someone help, here is code I am using
| > >
| > > Button One
| > >
| > > Private Sub Finnish_Click()
| > > ActiveWorkbook.Save
| > > ActiveWorkbook.SaveAs Filename:="C:\Questionaire.xls"
| > > Unload Me
| > > UserForm3.Show
| > > End Sub
| > >
| > > Button Two
| > >
| > > Private Sub UserForm_Click()
| > >
| > > Unload Me
| > > End Sub
| > >
| > >
| > > Thanks
 
Hi Jim,

Thanks for the reply, that worked brilliantly,

Dont suppose you can tell me why they way that I was doing it wasn't
working, just like to know for next time.

Thanks Phil
 
Well, the problem is that when you unload a userform in a sub it doesn't
really unload until that sub is done running. And since that sub opened
another userform that sub is not done until the second form is closed. It
can get messy. Using OnTime breaks the connection because it allows the sub
with the unload to complete before the code that opens the second form is
run.

--
Jim
| Hi Jim,
|
| Thanks for the reply, that worked brilliantly,
|
| Dont suppose you can tell me why they way that I was doing it wasn't
| working, just like to know for next time.
|
| Thanks Phil
|
| "Jim Rech" wrote:
|
| > Create a new sub in a standard module that shows the second form:
| >
| > Sub OpenSecondForm()
| > UserForm3.Show
| > End Sub
| >
| > Back in Sub Finnish_Click replace:
| >
| > UserForm3.Show
| >
| > with
| >
| > Application.OnTime Now, "OpenSecondForm"
| >
| > --
| > Jim
| > | > | Hi Joel,
| > |
| > | Thanks for the reply, I have tried what you suggested but am still
getting
| > | the same problem, any other thoughts??
| > |
| > | Thanks
| > |
| > |
| > | "Joel" wrote:
| > |
| > | > Hide the userform before opening the 2nd userform. You don't need
the
| > unload.
| > | >
| > | > "Phil" wrote:
| > | >
| > | > > Hi,
| > | > >
| > | > > I have 2 forms on the first form is a button which saves the
current
| > work
| > | > > book, unloads the form and then opens the second form. The
problem is
| > when I
| > | > > click the first button the form does not shut and the second one
opens
| > over
| > | > > the top and when you click the button on the second form to shut
it
| > the whole
| > | > > thing crash's can someone help, here is code I am using
| > | > >
| > | > > Button One
| > | > >
| > | > > Private Sub Finnish_Click()
| > | > > ActiveWorkbook.Save
| > | > > ActiveWorkbook.SaveAs Filename:="C:\Questionaire.xls"
| > | > > Unload Me
| > | > > UserForm3.Show
| > | > > End Sub
| > | > >
| > | > > Button Two
| > | > >
| > | > > Private Sub UserForm_Click()
| > | > >
| > | > > Unload Me
| > | > > End Sub
| > | > >
| > | > >
| > | > > Thanks
| >
| >
| >
 
Thanks for that Jim, its much appreciated I am sure its not going to be the
last time that I have to do something like this.

Thanks PD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top