As for the form, the user enters the data, but if they need to add additional items (i.e. more people, property vehicles), I need the data to save to an excel file, but clear the form. I have been able to get the textboxes and rich textboxes to clear, but I am unsure how to have combo boxes clear out (go blank). Here is a snippet of what I've written for the text and rich textboxes. Intellisense won't let me select selectindex and I'm currently stuck.

For Each Me.cControl In Person.Controls
If (TypeOf cControl Is TextBox) Then
cControl.Text = ""
End If
If (TypeOf cControl Is RichTextBox) Then
cControl.Text = ""
End If
Next cControl

Recommended Answers

All 3 Replies

Try this :

Private Sub ClearCombo(ByVal MyCombo As ComboBox)
    MyCombo.Items.Clear()
End Sub

For Each ccontrol In Me.Controls
    If TypeOf ccontrol Is ComboBox Then
        ccontrol.Text = ""
        ClearCombo(ccontrol)
    End If
Next ccontrol

Sorry. Misunderstood. You could set

cmbMyCombo.SelectedIndex = -1

and that will unselect all

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.