PC Review


Reply
Thread Tools Rate Thread

Couldn'nt unload a form

 
 
Marcus
Guest
Posts: n/a
 
      11th Aug 2009
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 With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      11th Aug 2009
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 With Quote
 
Marcus
Guest
Posts: n/a
 
      12th Aug 2009
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing Access While Form Is In Print Preview Does Not Trigger Form Unload Event Stewart Berman Microsoft Access Form Coding 3 7th Jun 2010 03:15 AM
why? form couldn't refresh when using split form Jason Jiang Microsoft Access 1 21st Aug 2007 06:12 PM
form couldn't refresh when using split form Jason Jiang Microsoft Access 0 20th Aug 2007 01:21 PM
i couldn't open my excel files,it gives location couldn't find err =?Utf-8?B?SG96ZWZh?= Microsoft Excel Misc 1 21st Dec 2005 04:06 PM
Re: Unload form, load another, forget about original form Bob Microsoft VB .NET 1 9th Jul 2003 01:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:07 AM.