Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Aug 2001
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    "Validating" a UserForm (2000)

    First of all, thanks for all your great help on my past questions. Invaluable.

    I have a userform wherein the user inputs a student's data. What is a good and easy method to go about popping up an error and making the user retry when he/she leaves a field empty?

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: "Validating" a UserForm (2000)

    Something like this?

    <pre>Private Sub btOK_Click()
    If fmMyForm.tbMyText.Value = "" Then
    MsgBox "MyText can't be empty."
    Exit Sub
    End If
    fmMyForm.Hide
    End Sub
    </pre>

    Legare Coleman

  3. #3
    Star Lounger
    Join Date
    Aug 2001
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: "Validating" a UserForm (2000)

    Legare, thank you again. While I have you around, is there a way to control how many sheets are added into a workbook I create within a macro? I want to create a new workbook with only 1 sheet in it.

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: "Validating" a UserForm (2000)

    It there was more than one text box, one might add:
    <pre>Private Sub btOK_Click()
    If fmMyForm.tbMyText.Value = "" Then
    MsgBox "MyText can't be empty."
    fmMyForm.tbMyText.SetFocus
    Exit Sub
    End If
    fmMyForm.Hide
    End Sub
    </pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  5. #5
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: "Validating" a UserForm (2000)

    Try:

    <pre>Dim oNewBook As Workbook, iOldSheets As Integer
    iOldSheets = Application.SheetsInNewWorkbook
    Application.SheetsInNewWorkbook = 1
    Set oNewBook = Workbooks.Add
    Application.SheetsInNewWorkbook = iOldSheets
    </pre>

    Legare Coleman

Posting Permissions

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