View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Zarch Zarch is offline
external usenet poster
 
Posts: 22
Default Control names on userform

Hello again :-)

I have a userform on which there are some textboxes which I wish to check
whether or not they are blank. I am using a function, and passing the name of
the userform into it as FormToCheck. I have inserted the debug.print line in
the code while trying to fix my issue.

Function CheckForBlanks(FormToCheck)

' Checks form for blank entries

Dim Tbx As Control

CheckForBlanks = False

For Each Tbx In FormToCheck.Controls

Debug.Print Tbx.Name

If TypeName(Tbx) = "TextBox" Then
If Tbx.Text = "" Then ' Check if textbox is empty
MsgBox "Please fill in all fields"
CheckForBlanks = True
Exit Function
End If
End If
Next Tbx

End Function

The code seems to miss two of the textboxes called tbxChangeFormStartDate
and tbxChangeFormEndDate - instead it returns the names as Textbox1 and
Textbox2 and considers them as empty even when there is data on the form.

If I debug.print tbxChangeFormStartDate.text then I get the value in it!

Also I have a SpinButton named SpinButton1 (the default), but this shows as
SpinButton2 in the debug.print when the code runs.

What have I missed? Are the names for the textboses too long? They are in a
frame - could this affect things?

Many thanks,

Z