There are 4 ways that I can think of to do it. If you only have those textboxes on the userform, a class could be use. The Tag property for the textboxes could be used. You could check each as focus was lost. Or a loop like this:
Private Sub CommandButton3_Click()
Dim c As Control
Dim ans As Integer
ans = vbNo
For Each c In Me.Controls
If TypeName(c) = "TextBox" And c.Value = "" Then
ans = MsgBox(c.Name & " has no value. Insert the default?", vbYesNo)
If ans = vbYes Then
Select Case c.Name
Case "TextBox1": c.Value = "My Default Value"
Case Else: 'do nothing?
End Select
End If
End If
Next c
Unload Me
End Sub
You can change the c.Name in the MsgBox to say c.ControlTipText if you want to add a descriptive name for your textbox for the message. Of course you would need to change TextBox1 to the name of your textbox and add other Case lines for each of the default values that you want to insert if they click Yes.
Bookmarks