PDA

View Full Version : Solved: strange Unload Me behaviour



ndendrinos
10-20-2009, 05:02 PM
These are the codes:

Private Sub Workbook_Open()
Sheets("Invoice").Activate
Application.EnableEvents = False
Range("A17:D35").ClearContents
Application.EnableEvents = True
UserForm20.Show

End Sub


Private Sub CommandButton1_Click()
lastnum = Range("F2").Value
If lastnum = "" Then
invoicenumber = 1
Else
invoicenumber = lastnum + 1
End If
Range("F2").Value = invoicenumber
Dim ctl
For Each ctl In Me.Controls
If TypeOf ctl Is msforms.TextBox Then
ctl.Text = ""
End If
Next ctl
[F3,F5,F6].ClearContents
TextBox1.SetFocus
End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub

Private Sub CommandButton3_Click()
[A1].Activate
Unload Me
[B8].Activate

End Sub

The problem is with the "Unload Me" of comdbutton2

If I close and save the workbook while in any sheet except "Invoice"
comdbutton2 behaves normally.

IF while the workbook is open I navigate from any sheet to "Invoice" then again comdbutton2 behaves normally.

BUT if I close and save the workbook from sheet "Invoice" when I reopen the workbook it takes clicking twice the comdbutton2 to close it.

Is there something obvious that I'm missing?
Thank you

ndendrinos
10-20-2009, 05:26 PM
I think I solved this by moving cmdbutton2 to the top of the tab routine.( the original order was cmdbutton1 then2, then3)