+ Reply to Thread
Results 1 to 13 of 13

validation in useforms help

  1. #1
    Registered User
    Join Date
    11-12-2006
    Posts
    42

    validation in useforms help

    hi there i have 2 userforms that i have made, both on seperate worksheets they work but allow anything to be typed in. i set up validation on the worksheet but when i store the data from the user form to the worksheet, the validation on the worksheet cells is erased. so im thinking somehow i need to set up validation in the code of the forms in visual basics. can anyone help.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternooon diesel20056

    With textboxes on userforms you have to code your own data validation. Exactly how you do it depends on what sort of data you want to validate (dates, text, number, maximum, minimum etc). Can you be more specific?

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Registered User
    Join Date
    11-12-2006
    Posts
    42
    hi mate if i supply u the code and the validation criteria will u be able to do it please i really am a noob at this. i beeen trying all morning and its not happening

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi diesel20056

    if i supply u the code and the validation criteria will u be able to do it please
    If you're nice to me
    What's the criteria?

    DominicB

  5. #5
    Registered User
    Join Date
    11-12-2006
    Posts
    42
    customer user form

    Number, validation between 1-9999
    Title validtion list mr,miss,mrs,sir
    Surname validation text between 0-25 chars
    Age validation number between 18-80
    Address validation text between 0-80 chars
    Post Code validation text betweeb 0-chars
    Discount validation list yes/no

  6. #6
    Registered User
    Join Date
    11-12-2006
    Posts
    42
    code for form

    Private Sub cmdClearForm_Click()
    TxtNumber.Text = ""
    TextTitle.Text = ""
    TextSurname.Text = ""
    TextAge.Text = ""
    TextAddress.Text = ""
    TextPostcode.Text = ""
    ComboBox1.Text = ""

    End Sub

    Private Sub ComboBox1_Change()

    End Sub

    Private Sub CommandButton1_Click()
    Unload Me
    End Sub

    Private Sub CommandButton3_Click()
    Dim varNbRows As Double
    Sheets("customer database").Select
    Range("A1").Select
    varNbRows = Selection.CurrentRegion.Rows.Count
    If Selection.Value = "" Then
    Exit Sub
    ElseIf Selection.Offset(1, 0).Value = "" Then
    Selection.Offset(1, 0).Select
    Else
    Selection.Offset(varNbRows, 0).Select
    End If
    Range("A1")(ActiveCell.Row).Value = TxtNumber.Text
    Range("B1")(ActiveCell.Row).Value = TextTitle.Text
    Range("C1")(ActiveCell.Row).Value = TextSurname.Text
    Range("D1")(ActiveCell.Row).Value = TextAge.Text
    Range("E1")(ActiveCell.Row).Value = TextAddress.Text
    Range("F1")(ActiveCell.Row).Value = TextPostcode.Text
    Range("G1")(ActiveCell.Row).Value = ComboBox1.Text



    End Sub


    Private Sub Frame1_Click()

    End Sub

    Private Sub TextTitle_Change()

    End Sub


    Private Sub UserForm_Click()

    End Sub

  7. #7
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi diesel20056

    This code should validate your textboxes for you :

    Please Login or Register  to view this content.
    There isn't a validation routine for your yes/no combobox - just make sure that in the properties window, the MatchRequired field is set to True.

    HTH

    DominicB

  8. #8
    Registered User
    Join Date
    11-12-2006
    Posts
    42
    the match field thing is that for all of them or jus the combo box mate

  9. #9
    Registered User
    Join Date
    11-12-2006
    Posts
    42
    one problem now none of my macro's work when i click tjhem the no! error box comes up and only the number and title fields work the error box comes up when i select the otehr texxt boxes
    Last edited by diesel20056; 11-21-2006 at 06:40 AM.

  10. #10
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi diesel20056

    Yes, because the boxes are validated when you try and exit them. When you click on a macro to run, are all the boxes filled out with the infomration they are supposed to have? If all the boxes are filled out correctly, the macros should run.

    BTW, only set the MatchRequired field on the combobox object.

    HTH

    DominicB

  11. #11
    Registered User
    Join Date
    11-12-2006
    Posts
    42
    by the way the tiltle box at the moment is a text box and no list shows do i make it into al ist box for the list to show>?

  12. #12
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Hi diesel20056

    Look at the attached workbook. It uses the code I posted, validates to the rules you specified and works OK for me. When you click either of the option buttons you will get an error if the boxes haven't been filled out correctly.

    If this is not working as you imagined you will have specify exactly how, and what you expected to get versus what you actually did get.

    HTH

    DominicB
    Last edited by dominicb; 08-19-2008 at 04:29 AM.

  13. #13
    Registered User
    Join Date
    11-12-2006
    Posts
    42
    thanks alot mate it works now, very much appreciated

+ 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