Consulting

Results 1 to 3 of 3

Thread: Validating Sheet

  1. #1
    VBAX Regular
    Joined
    Feb 2006
    Posts
    28
    Location

    Validating Sheet

    Hi,

    I was wondering how to validate a sheet before it can be saved, i have a few texts boxes and fields that need filling out, however i would like to force the user to fill out all of the fields before it can be saved...

    I have a little knowledge of VBA if i would need to go that route.

    Thanks

    C19

  2. #2
    Quote Originally Posted by c19h28O2
    I was wondering how to validate a sheet before it can be saved, i have a few texts boxes and fields that need filling out, however i would like to force the user to fill out all of the fields before it can be saved...

    Hi,

    Here's a simple way to handle it. If you have to click CommandButton1 to exit the form, add this code to the UserForm code page:

    [VBA]Private Sub CommandButton1_Click()
    Dim ctl As Control
    For Each ctl In Me.Controls
    If Left(ctl.Name, 7) = "TextBox" Or Left(ctl.Name, 8) = "ComboBox" Then
    If ctl.Value = "" Then
    MsgBox ("You didn't fill out the form completely." & Chr(13) & _
    "Please fill in the blanks")
    Exit Function
    End If
    End If
    Next ctl

    'Do the rest of your stuff here

    End Sub[/VBA]

    Hope that helps,

    Rembo

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,002
    Location
    Cross post on Mr Excel board
    Peace of mind is found in some of the strangest places.

Posting Permissions

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