UserForm and .hide: prevent code from further execution

  • Thread starter Thread starter Christian
  • Start date Start date
C

Christian

Hi,

I can show a Userform by "SampleUserForm.Show" and make it dissapear
by "SampleUserForm.hide"
So far, so good.

I created code which might produce a division by zero, depending on
former input. My code (simplified UserForm):


Private Sub Calculation

If a <= 0 Then
Calculation.Hide ' Just this UserForm should "hide"/disappear
and code in just this Userform should stop
End If

b = Log (a) ' This leads to an error (division by zero)
if a <= 0

End Sub


So ".Hide" makes the UserForm disappear but keeps the code running.
Otherwise "Stop" (or is it "Halt"?) would make the whole program stop.
I'm searching for a possibility to hide the UserForm and prevent the
code in this UserForm from going on.

Thanx for any suggestions,

- Christian
 
Hi Christian,

Try something like:

'=============>>
Private Sub CommandButton1_Click()
Dim a As Double
Dim b As Double

If a <= 0 Then
Unload Me
Exit Sub
End If
b = Log(a)
End Sub
'<<============
 
Hi Christian,

Try something like:

'=============>>
Private Sub CommandButton1_Click()
Dim a As Double
Dim b As Double

If a <= 0 Then
Unload Me
Exit Sub
End If
b = Log(a)
End Sub
'<<============



Thank you very much, that's it!
 

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