+ Reply to Thread
Results 1 to 11 of 11

How to check Required field Not Empty with "Tag = Optional"

  1. #1
    Registered User
    Join Date
    11-07-2017
    Location
    Austin, TX
    MS-Off Ver
    2010
    Posts
    22

    Exclamation How to check Required field Not Empty with "Tag = Optional"

    Hello,

    I have a Multi-Page Userform with text, list, and combo boxes. The non-required fields have Tag = "Optional". How do I run a [field <> Empty] check on the required controls? I'd like to pause the check, SetFocus on the empty field so the user can fill it out, and then resume the check.

    Thank you.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to check Required field Not Empty with "Tag = Optional"

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    11-07-2017
    Location
    Austin, TX
    MS-Off Ver
    2010
    Posts
    22

    Re: How to check Required field Not Empty with "Tag = Optional"

    Thank you for this. I will try it.

    Question -- why TextBox2.Tag = "Must" ?

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to check Required field Not Empty with "Tag = Optional"

    As a test I set all the controls to "Optional".

    I then set TextBox2 to "Must" ie not "Optional".

    The last part loops through all the controls until it finds one that is not "Optional" ie Textbox2.

    It sets focus to Textbox2 and then quits.

  5. #5
    Registered User
    Join Date
    11-07-2017
    Location
    Austin, TX
    MS-Off Ver
    2010
    Posts
    22

    Re: How to check Required field Not Empty with "Tag = Optional"

    so if I want to search for empty "required" fields, then this?

    Private Sub UserForm_Activate()
    For Each c In Me.Controls
    If c.Tag <> "Optional" Then
    if c.value = "" then c.SetFocus: Exit For
    Next
    End Sub

    Thanks for your help!

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to check Required field Not Empty with "Tag = Optional"

    Please Login or Register  to view this content.
    I should mention that testing for a group of option buttons is not included in that code.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  7. #7
    Registered User
    Join Date
    11-07-2017
    Location
    Austin, TX
    MS-Off Ver
    2010
    Posts
    22

    Re: How to check Required field Not Empty with "Tag = Optional"

    Hi Mike,
    Thanks for this -- Question: why NotFilled = (c.Text = vbNullString) ?

    Also, how do I make it SetFocus at each empty required field?

    Thanks for any light you can shed.

  8. #8
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to check Required field Not Empty with "Tag = Optional"

    The variable NotFilled is set to True when the control is empty, i.e. when c.Text = VbNullString.

    After the EndSelect, you should test NotFilled and take the appropriate action.

  9. #9
    Registered User
    Join Date
    11-07-2017
    Location
    Austin, TX
    MS-Off Ver
    2010
    Posts
    22

    Exclamation Required Field check flags empty field but can't set focus

    I got it to work with code below. However, SetFocus no longer works.
    I get this error: Capture.PNG

    Please Login or Register  to view this content.
    Any suggestions would be much appreciated.
    Thanks again!

  10. #10
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to check Required field Not Empty with "Tag = Optional"

    Please Login or Register  to view this content.


    Or:-


    Please Login or Register  to view this content.
    Last edited by mehmetcik; 11-11-2017 at 06:24 PM.

  11. #11
    Registered User
    Join Date
    11-07-2017
    Location
    Austin, TX
    MS-Off Ver
    2010
    Posts
    22

    Re: How to check Required field Not Empty with "Tag = Optional"

    Thank you. This sub will run when User gets ready to save & send back to me--so it checks all the "REQUIRED" controls and then changes the background of field (and ControlSource) to yellow if empty [FieldEmpty Ctrl]. Then once the User fills out the fields and tries to save & send again, it'll run through the controls again and clears background color if field is filled [NotEmpty Ctrl].

    So should I SetFocus and pause the sub until the field has been filled out? If so, how do I loop it until it checks all the controls?
    Thanks again.

+ 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. How to check "Product activation required" warning?
    By HerryMarkowitz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-09-2016, 07:33 AM
  2. Replies: 5
    Last Post: 01-23-2014, 11:02 AM
  3. Exclude specific box from "check if any box is empty" code
    By Zer0aim in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2013, 04:15 AM
  4. [SOLVED] Cell returning the value of "0", required it to be empty
    By miss_chloe in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-26-2013, 11:38 AM
  5. Replies: 2
    Last Post: 06-06-2013, 12:45 PM
  6. Empty cells but still being being recognized by my "last column" check
    By chemeng1T4 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2012, 12:25 PM
  7. [SOLVED] create links to check boxes marked "good" fair"and "bad"
    By pjb in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-19-2006, 09:25 PM

Tags for this Thread

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