Consulting

Results 1 to 2 of 2

Thread: Solved: strange Unload Me behaviour

  1. #1
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location

    Solved: strange Unload Me behaviour

    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
    Thank you for your help

  2. #2
    VBAX Mentor
    Joined
    Sep 2004
    Posts
    431
    Location
    I think I solved this by moving cmdbutton2 to the top of the tab routine.( the original order was cmdbutton1 then2, then3)
    Thank you for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •