Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Couldn'nt unload a form

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€¦

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Couldn'nt unload a form

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


"Marcus" wrote:

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€¦

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Couldn'nt unload a form

Thanks Joel...

"Joel" wrote:

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


"Marcus" wrote:

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€¦

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to unload a form Grd Excel Programming 3 March 20th 07 03:48 PM
How to unload a form in excel vba? Edward[_7_] Excel Programming 2 September 30th 04 04:39 PM
Unload the form on esc key Papou Excel Programming 0 August 10th 04 05:15 PM
form won't unload inquirer Excel Programming 1 May 26th 04 09:55 AM
Form Unload Khai[_2_] Excel Programming 0 August 4th 03 09:28 PM


All times are GMT +1. The time now is 09:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"