Results 1 to 7 of 7

Checking for empty textbox and setfocus the empty textbox

Threaded View

  1. #1
    Forum Contributor
    Join Date
    08-24-2012
    Location
    Hollidaysburg, Pa
    MS-Off Ver
    Excel 2010
    Posts
    398

    Checking for empty textbox and setfocus the empty textbox

    Want the command button to check if any of the many textboxes in a userform are empty.

    If empty, Want the macro to
    • setfocus on that textbox
    • Message box (pls enter the value)

    tried this

    Private Sub CommandButton1_Click()
    
    Dim ctl As Control
    
        
        For Each ctl In Controls
       If TypeOf ctl Is TextBox Then
          If IsNull(ctl.Value) = True Then
          ctl.SetFocus
          GoTo lastline
             
             Exit Sub
          End If
       End If
    Next
    lastline:        MsgBox "Data is required"
    End Sub
    Problem :

    Doesn't setfocus the empty textbox
    Last edited by subbby; 05-23-2013 at 02:50 PM. Reason: Solved

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1