Results 1 to 4 of 4

Thread: Newbie question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Brighton, England
    Posts
    112
    The best way is to use an If, then statement and pop up a messsage box if a text box is blank , then when they OK the message box you can set focus back to that text box. Here's a little code sample:


    'put this code in the click event or the event you use to check the text box contents
    Dim iMsg As Integer
    '
    If txt1.Text = "" Then
    iMsg = MsgBox("Please enter some text in text 1", vbOKOnly, "Missing entry")
    txt1.SetFocus
    Exit Sub
    '
    ElseIf txt2.Text = "" Then
    iMsg = MsgBox("Please enter some text in text 2", vbOKOnly, "Missing entry")
    txt2.SetFocus
    Exit Sub

    'etc
    'etc

    End If


    hope this helps

    cheers

    john

  2. #2
    billfaceuk
    Guest
    If Text?.Text="" Then
    msgbox "Fill in the field idiot!",vbCritical+vbokonly
    exit sub
    else
    'code to fill in database
    end if

    OR

    If Text?.Text="" Then
    msgbox "Fill in the field idiot!",vbCritical+vbokonly
    exit sub
    end if
    'code to fill in database

  3. #3
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Add 1 box named txtArray and copy, then paste

    Click yes when it asks do you want to create a control array

    the put this code on your button:

    Code:
    Private Sub Command1_Click()
    Dim ErrorsFound As Integer, i As Integer
    ErrorsFound = 0
    For i = 0 To txtArray.Count - 1
        If txtArray(i).Text = "" Then
            ErrorsFound = ErrorsFound + 1
        End If
    Next i
    If ErrorsFound <> 0 Then
        MsgBox ErrorsFound & " errors were found! Please rectify this situation", vbOKOnly
        Exit Sub
    End If
    
    'Database Addition Code
    End Sub
    or download the following form
    Attached Files Attached Files

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'Clear all textboxs on all forms or all textboxes on a single form
    'You can do it this way without an array..but an array would be quicker
    'if you were dealing with a lot of controls on a form
    
    Option Explicit
    '
    Public Sub CheckTxt()
    
    Dim ctlMyControl As Control
    Dim intIncrement As Integer
    
    For intIncrement = 0 To Forms.Count - 1
    For Each ctlMyControl In Forms(intIncrement).Controls
    
    If TypeOf ctlMyControl Is TextBox Then
       If ctlMyControl.Text = "" Then
        MsgBox "Sorry, you need to fill in all textboxes"
        ctlMyControl.SetFocus
        Exit Sub
        End If
    End If
    '
    Next ctlMyControl
       Next intIncrement
    
    End Sub
    
    Private Sub Command1_Click()
       Call CheckTxt
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

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



Click Here to Expand Forum to Full Width