how can i create a function/procedure/control array that will tell which textbox on my form doesn't have any text in it and set the focus to that one? thank you.
Printable View
how can i create a function/procedure/control array that will tell which textbox on my form doesn't have any text in it and set the focus to that one? thank you.
If TextBox1.Text = "" Then
TextBox1.Focus()
End If
??
if i have a form with 20 text boxes on it, i would rather not do the if then statements, i'm trying to make a nice little function that would return either true or false if it has text.
Try this.
VB Code:
Dim ctrl As Control For Each ctrl In Me.Controls If (TypeOf ctrl Is TextBox) Then If (ctrl.Text = "") Then ctrl.Focus() End If End If Next
You're going to have to use atleast one if then statement.Quote:
Originally posted by gmatteson
if i have a form with 20 text boxes on it, i would rather not do the if then statements, i'm trying to make a nice little function that would return either true or false if it has text.
I just showed you an example of what you asked for.
Mem's code will work, the only problem is if you have more than 1 empty textbox, then his is going to set focus to each one until the loop is finished executing so it'll always go to the last one.
actually the code will set the focus to the first textbox that is empty, then move on to the next one, etc..
thank you.