PDA

View Full Version : Solved: Checking textboxes and combo for content



paddy69
02-09-2007, 06:21 AM
I have a userform with several textboxes, option buttons (in a separate frame) and combos. Not all textboxes, option buttons and combos on the form are enabled but I want to check before a user clicks the OK button that all enabled textboxes, option buttons and combos are filled in. How can I do that?

fumei
02-09-2007, 08:50 AM
First question....what method are you using to read the user's mind to know they are just about to click the OK button?

Second question...why do you have disabled controls?

I am be facetious BTW. The simple answer is that unless you DO have some way of reading the user's mind (that they are going to click OK), you can not do this.

However, the simple answer is....

Do it when they click the OK button. There are various ways to do it, and as I can't see your userform I can only suggest the brute force method.

Sub Blah_Click()
Dim blnUnFinished As Boolean
If Me.Textbox1.Text = "" Then
blnUnFinished = True
End If
If Me.ComboBox1.ListIndex = 0 Then
blnUnFinished = True
End If

If blnUnFinished = True Then
Msgbox "Incomplete data entry. Please fill in " & _
"all fields."
Exit Sub
Else
' do whatever a completed form does
End If
End SubProperly done, you would add logic to keep track of which control is not completed, and return focus to that control.