+ Reply to Thread
Results 1 to 5 of 5

Call userform_initialize to clear userform not working

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-27-2010
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2007
    Posts
    115

    Call userform_initialize to clear userform not working

    Hi,

    I created a cmdButton to clear the data filled in the userform.
    The code is correct, but it only clears the information from the textboxes, not from the comboboxes.
    I t has to be related to the Userform_Initialize code, but i can't figure it out.

    Can anyone help me?
    Thanks in advance
    Private Sub cmdlclear_Click()
    Dim confirm As Integer
    confirm = MsgBox("are you certain you want to delete form?", vbYesNo + vbQuestion)
    If confirm = vbYes Then
    Call UserForm_Initialize
    End If
    End Sub
    
    Private Sub UserForm_Initialize()
        txtdataregisto = Format(Date, "dd-mm-yyyy")
        txtID = valmax + 1
        txtdossier.Value = ""
        txtvalor.Value = ""
        txtdataentrega.Value = ""
        txtdataregularização.Value = ""
        txtjurosindevidos.Value = ""
        txtvalordeseguro.Value = ""
        txtanulaçãodeis.Value = ""
        txtanulaçãopenalidades.Value = ""
        txtvalorrealpassagemaperdas.Value = ""
        
     Me.cbocolaborador.List = Worksheets("Listas").Range("c3:c8").Value
     Me.cboproduto.List = Worksheets("Listas").Range("B3:B13").Value
     Me.cbooperação.List = Worksheets("Listas").Range("d3:d14").Value
     Me.cbomotivo.List = Worksheets("Listas").Range("e3:e13").Value
     Me.cboparceiro.List = Worksheets("Listas").Range("a3:a165").Value
         End Sub

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Call userform_initialize to clear userform not working

    Try this
    Private Sub UserForm_Initialize()
    With Me
        .txtdataregisto = Format(Date, "dd-mm-yyyy")
        .txtID = valmax + 1
        .txtdossier.Value = ""
        .txtvalor.Value = ""
        .txtdataentrega.Value = ""
        .txtdataregularização.Value = ""
        .txtjurosindevidos.Value = ""
        .txtvalordeseguro.Value = ""
        .txtanulaçãodeis.Value = ""
        .txtanulaçãopenalidades.Value = ""
        .txtvalorrealpassagemaperdas.Value = ""
     .cbocolaborador.List = Worksheets("Listas").Range("c3:c8").Value
     .cboproduto.List = Worksheets("Listas").Range("B3:B13").Value
     .cbooperação.List = Worksheets("Listas").Range("d3:d14").Value
     .cbomotivo.List = Worksheets("Listas").Range("e3:e13").Value
     .cboparceiro.List = Worksheets("Listas").Range("a3:a165").Value
      .cbocolaborador.ListIndex = -1
     .cboproduto.ListIndex = -1
     .cbooperação.ListIndex = -1
     .cbomotivo.ListIndex = -1
     .cboparceiro.ListIndex = -1
    End With
         End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Call userform_initialize to clear userform not working

    Find out (VBEditor F1) the difference between _Initialize and _Activate

    Private Sub cmdlclear_Click()
      If  MsgBox("are you certain you want to clear the form?", vbYesNo + vbQuestion)= vbYes Then UserForm_Activate
    End Sub
    
    Private Sub UserForm_Initialize()
       With Sheets("Listas")
         cbocolaborador.List = .Range("c3:c8").Value
         cboproduto.List = .Range("B3:B13").Value
         cbooperação.List = .Range("d3:d14").Value
         cbomotivo.List = .Range("e3:e13").Value
         cboparceiro.List = .Range("a3:a165").Value
      End With
    End Sub
    
    Private Sub UserForm_Activate()
        For each ctl in controls
          Select case typename(ctl)
          Case "Textbox"
            .Text=""
          Case "ComboBox"
            .listindex=-1
          End Select
        Next
    
        txtdataregisto = Format(Date, "dd-mm-yyyy")
        txtID = valmax + 1
    End Sub

  4. #4
    Forum Contributor
    Join Date
    04-27-2010
    Location
    Lisbon, Portugal
    MS-Off Ver
    Excel 2007
    Posts
    115

    Re: Call userform_initialize to clear userform not working

    It works great...

    Thanks to both of you.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Call userform_initialize to clear userform not working

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1