Dim ctl As Control For Each ctl In Me.Controls If TypeOf (ctl) Is TextBox Then If ctl.Text = "" Then MsgBox("Please Enter the text ", MsgBoxStyle.Information, "Note") Else ctl.Focus() End If End If Next
Dim ctl As Control For Each ctl In Me.Controls If TypeOf (ctl) Is TextBox Then If ctl.Text.Length = 0 Then MsgBox("Please Enter the text ", MsgBoxStyle.Information, "Note") Else ctl.Focus() End If End If Next
Dim ctl As Control For Each ctl In Me.Controls If TypeOf (ctl) Is TextBox Then 'In this next line, I added a .Trim to get rid of spaces and used theanil's method of using the .Length and comparing it to zero instead of checking for an empty string. If ctl.Text.Trim.Length = 0 Then MsgBox("Please Enter the text ", MsgBoxStyle.Information, "Note") 'I removed the else because I figured you wanted to set focus when the box was empty ctl.Focus() 'I added the Exit For because once you've found an empty box you want to stop your checking Exit For End If End If Next
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)