Couldn'nt unload a form

M

Marcus

I have 3 userforms, the form3 has 2 buttons to open the others, the code that
I am using to change among these forms is:

Private Sub cmdcancel_Click()
Unload Me
UserForm3.Show
End Sub

The problem is on form1 this form has a textbox that has the below
validation code to work, when I write all the information correct and run the
process and then click on the “cmdcancel†button to change to form3
everything works well but if I write a incorrect data and then try to click
on the “cmdcancel†button the form1 or 2 remain open. I am stock in this part
could you help me with this issue?


If Trim(Me.txtlsize.Value) = "" Then
Me.txtlsize.SetFocus
MsgBox "Please enter a Lot size"
Exit Sub
End If
If Me.txtlsize.Value <= 1 Then
Me.txtlsize.SetFocus
MsgBox "Invalid Lot size"
Exit Sub
End If
If Not IsNumeric(Trim(Me.txtlsize.Value)) Then
Me.txtlsize.SetFocus
MsgBox "Invalid Lot size"
Exit Sub
End If

The code continues…
 
J

Joel

You are exiting the Sub when an error occurs so you are never getting to the
code which closes the userform. The code is correct

You may want to reverse these two instruction so the txtbox gets the focus
after the msgbox is closed

from
Me.txtlsize.SetFocus
MsgBox "Please enter a Lot size"

to
MsgBox "Please enter a Lot size"
Me.txtlsize.SetFocus
 
M

Marcus

Thanks Joel...

Joel said:
You are exiting the Sub when an error occurs so you are never getting to the
code which closes the userform. The code is correct

You may want to reverse these two instruction so the txtbox gets the focus
after the msgbox is closed

from
Me.txtlsize.SetFocus
MsgBox "Please enter a Lot size"

to
MsgBox "Please enter a Lot size"
Me.txtlsize.SetFocus
 

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

Top