+ Reply to Thread
Results 1 to 4 of 4

verifying multiple text boxes are not empty

Hybrid View

h_aesa1 verifying multiple text boxes... 11-13-2009, 09:58 PM
D_Rennie Re: verifying multiple text... 11-14-2009, 12:43 AM
D_Rennie Re: verifying multiple text... 11-14-2009, 12:44 AM
h_aesa1 Re: verifying multiple text... 11-14-2009, 11:07 AM
  1. #1
    Registered User
    Join Date
    02-09-2009
    Location
    Washington, US
    MS-Off Ver
    Excel 2003
    Posts
    73

    verifying multiple text boxes are not empty

    I have a form and I am trying to do the following:

    I have many text boxes on a form and if any of them are empty then I want a msgbox to popup and exit sub

    I know how to do the following

    If txtExample1 is "" then msgbox and exit sub
    if txt....2
    if txt...3

    and so on

    Is there anyway to group the text boxes to test for empty so you don't have to list 20 textboxes

    thanks,

    JJ
    Last edited by h_aesa1; 11-14-2009 at 11:08 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: verifying multiple text boxes are not empty

    hello.

    you can loop the textbox controlls like.
     Dim oCtrl      As MSForms.Control ' Textbox Data Cheek
            For Each oCtrl In Me.Controls
                If TypeOf oCtrl Is MSForms.TextBox Then MsgBox "The Textbox " & oCtrl.Name & " Needs A valid entry"
            Next oCtrl
    you could add code to this to skip certian textboxs based on the controll name.
    hope this helps

    here is the other method that i know to loop the controls
    Dim txtArray As Variant
    Dim LpArr As Integer
    txtArray = Array("Textbox1", "Textbox2", "Textbox3")
    For LpArr = LBound(txtArray) To UBound(txtArray)
        If Me.Controls(LpArr).Value = "" Then
            Select Case LpArr
                Case 0
                    MsgBox "This it the 1st control in array"
                Case 1
                    MsgBox "this is the second control in array"
                Case 2
                    MsgBox "this is the 3rd control in array"
                Case Else
                    MsgBox "This message sould not get seen"
            End Select
        End If
    Next LpArr
    Last edited by D_Rennie; 11-14-2009 at 03:22 AM.


  3. #3
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: verifying multiple text boxes are not empty

    del double post
    Last edited by D_Rennie; 11-14-2009 at 12:48 AM.

  4. #4
    Registered User
    Join Date
    02-09-2009
    Location
    Washington, US
    MS-Off Ver
    Excel 2003
    Posts
    73

    Re: verifying multiple text boxes are not empty

    thanks, I believe it is working, I used the 2nd one as I may have different msgbox responses depending on text box.

    thanks

    JJ

+ Reply to Thread

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