+ Reply to Thread
Results 1 to 2 of 2

Userform Validation - combining code?

  1. #1
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Userform Validation - combining code?

    Userform is adding info for up to 20 people (Potential for 8 adults labeled Adult1, adult2..... and 12 children labeled Child1, child 2....)

    for each of the people, I have to run the same validations.

    1. If a first name is entered there MUST be a last name entered
    2. If a last name is entered there MUST be a first name entered
    3. If a first name and last name is entered a DOB must be entered
    4. If a first name and last name is entered then a validation yes/no box is to be checked.

    I am basically looking to try and combine the macro code behind the scenes in an effort to optimize.

    Example of DOB Validation code is

    is there any way to do this?
    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,163

    Re: Userform Validation - combining code?

    First, is it important to validate as the user is filling out information, forcing them to fill it out in a specific order? If so then I would suggest managing the user interface accordingly:

    Disable all controls except last name
    After last name is entered, enable first name
    After first name is entered, enable DOB and Yes/No boxes

    The way I would do this (certainly not the only way possible) starts with renaming all of your controls to match how they're used. If you do not do this, the code is a nightmare. (I find the code in this file to be unreadable for this reason. There are maybe dozens of textboxes and you can't figure out what is what in the code.) For example,

    TextBoxAdultFirst1
    TextBoxAdultLast1
    TextBoxAdultDOB1
    ComboBoxAdultRelation1
    CheckBoxAdultVerifiedYes1
    CheckBoxAdultVerifiedNo1

    TextBoxAdultFirst2
    TextBoxAdultLast2
    TextBoxAdultDOB2
    ComboBoxAdultRelation2
    CheckBoxAdultVerifiedYes2
    CheckBoxAdultVerifiedNo2

    Then you have code like this:
    Please Login or Register  to view this content.
    You would repeat this for each field. When you have to actually validate the contents, like DOB, you can have a validation Sub:

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Userform textbox validation - non-existent date validation
    By rbngrt582 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2018, 10:14 PM
  2. Combining my userform with a userform template - 'find' and 'amend' feature
    By excelconditional in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-19-2017, 04:13 AM
  3. [SOLVED] Userform for canadian postal code validation?
    By calvinle in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-01-2014, 01:03 PM
  4. combining code to have userform get data from 1 sheet and transfer to another
    By James__S in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2014, 03:26 AM
  5. combining chart userform and data transfer userform into 1 userform
    By H_Kennedy in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 01-04-2014, 07:11 AM
  6. combining chart userform and data transfer userform into 1 userform
    By H_Kennedy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-03-2014, 12:28 PM
  7. [SOLVED] Combining Validation (empty and numeric) Code for ActiveX Text Box
    By VB@N3wb|3 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-13-2012, 10:22 PM

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