+ Reply to Thread
Results 1 to 12 of 12

Change UserForm background color when a date is filled in

  1. #1
    Registered User
    Join Date
    09-06-2018
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2016
    Posts
    21

    Change UserForm background color when a date is filled in

    Greetings all!

    I have a UserForm named DataUF that I want to change the background color on when a date is entered into a Date Picker.

    Right now the Date Picker is just the basic code. Checkboxes are enabled in it ("True") so if the checkbox is unchecked no color change should happen or change back to the normal color. But when it is checked they may choose a date and that date should change the background color of the UserForm DataUF. The Date Picker is named DTPDateFLWRrcvd.

    Please Login or Register  to view this content.
    I hope I have enough detail above for you to help. Please let me know if you need more. Thanks for the help.
    ? ProfXer

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Change UserForm background color when a date is filled in

    .

    Paste in the UserForm :


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    09-06-2018
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2016
    Posts
    21

    Re: Change UserForm background color when a date is filled in

    Thanks for the quick response, Logit. Unfortunately, I cannot get it to work. Perhaps I mislead you in focusing on the checkbox in the Date Picker. The checkbox of the Date Picker only toggles the ability of showing a date or not showing a date. So, I'm not sure if a click is functional on Date Pickers. I wonder if it would be functional to have the code focus on the value of the Date Picker either being "" or not "".

    Below is the code as I adapted it from yours.

    Please Login or Register  to view this content.
    What do you think?

  4. #4
    Registered User
    Join Date
    09-06-2018
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2016
    Posts
    21

    Re: Change UserForm background color when a date is filled in

    I know I have obviously done something wrong. Below is the code that involves the UserForm.

    Please Login or Register  to view this content.
    When I try to run and update a record with this code, it pops an error at the first line of code I have copied for you. Perhaps I have it in the wrong place. The error is:

    "Compile error:
    Only comments may appear after End Sub, End Function, or End Property"

    I value your input. Thanks.

  5. #5
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Change UserForm background color when a date is filled in

    .
    I cannot attest to the accuracy of your macro code. It is presumed to be correct.

    The overall layout of the macros should be like this :

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-06-2018
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2016
    Posts
    21

    Re: Change UserForm background color when a date is filled in

    Logit, I have the code in place and no errors are flagged now. Progress! But when I put a date in the Date Picker nothing changes. Is it that while the Date Picker has a checkbox, it cannot be coded as a checkbox? When I click the checkbox, the only change in value is from "" (blank) to containing the date picked (see pictures below).

    FLWR-DTP-NOdate.JPG
    FLWR-DTP-date.JPG

  7. #7
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Change UserForm background color when a date is filled in

    .
    Please post your workbook for review. Do Not include any confidential information.

    What are you expecting to occur when you check the checkbox ... and when you uncheck the checkbox ?

  8. #8
    Registered User
    Join Date
    09-06-2018
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2016
    Posts
    21

    Re: Change UserForm background color when a date is filled in

    It took a while, but I finally sanitized the workbook for posting. The User Form is accessed via the "ADD" or "EDIT" buttons on the Data tab. The EDIT button is the one I'm mainly interested in getting up and running.

    Unfortunately, I cannot seem to attach a file. I've even tried it in Firefox & Chrome. Nor have I had much success with the site search engine to find instructions to attach workbook.

  9. #9
    Registered User
    Join Date
    09-06-2018
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2016
    Posts
    21

    Re: Change UserForm background color when a date is filled in

    I think I may have found something that allows an upload. At any rate, when a date is entered in the form for "Date FLWR Received" (DTPDateFLWRrcvd) the action to change the UserForm, DataUF, should be triggered. To enter a date, one must click on the radio button of the Date Picker.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    09-06-2018
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2016
    Posts
    21

    Re: Change UserForm background color when a date is filled in

    I was able to adapt the code Logit provided and make the form change color immediately upon clicking the checkbox to use the date picker. However, when I unclick the Date Picker the color remains changed and does not return to the original color. So something is still not quite right.

    The code below assumes that the date picker Value returns to "" when the picker checkbox is not checked. Somehow I suppose I need to have the code re-evaluate any time the checkbox is checked or unchecked. I'm not sure how to do that since date pickers are not true checkboxes.

    I also just noticed that when I close out the User Form and reopen the same record, the color has reverted to blue (the original color) even though the checkbox for DTPDaateFLWRRcvd is checked. That's a problem.

    Please Login or Register  to view this content.
    I appreciate Logit's code setting me out into a good direction.

    Thanks for your insights,
    Last edited by ProfXer; 10-16-2018 at 03:45 PM.

  11. #11
    Registered User
    Join Date
    09-06-2018
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2016
    Posts
    21

    Re: Change UserForm background color when a date is filled in

    I have also noticed that date pickers do not work with Win10 OS natively. One must install the lacking files extracted from MSCOMCT2.OCX. Since this means not every machine will be able to run this code I've worked so hard to produce, I am considering taking out the date pickers and putting in mere text boxes with date data validation. Not as classy, but more portable. In that event, the object I will be wanting to write code against is a text box. In fact, even this might not serve me well enough. I will need up to 3 different criteria that will change the form backcolor.

    One criteria is the above date of the returned FLWR being filled out. I'd like this to be immediately effective when someone fills in a date or deletes it (makes it blank) in the userform.
    The next criteria is when the status contains the word "connected" (this will include "connected" and "not connected"
    Another possible criteria is a status of "disqualified"

    One solution I see is to use helper columns for each entry. I could right a formula that results in true or false for each of these criteria. However, I would not see immediate color change on the first criteria since that information has yet to be written to the spreadsheet from the form.

    Do you think this solution will be less problematic than the date pickers?

  12. #12
    Registered User
    Join Date
    09-06-2018
    Location
    Georgia, USA
    MS-Off Ver
    Excel 2016
    Posts
    21

    Re: Change UserForm background color when a date is filled in

    I am still searching for a solution to the problem. I dumped the Microsoft built in date pickers due to not being usable on all PCs the file is opened in. Using Trevor Eyre's VBA code date picker and it works great. So now in stead of DatePicker's with check boxes, etc., I am using a text box associated with a command button.

    The objective is the same... change color of form when a date is filled in a specific text box (reverts to original color if the date is deleted from text box). The user form is named DataUF and the target text box is TxtDateFLWRrcvd. So if the form is opened and a date is already filled in (from the spreadsheet it reads from) it should turn color from default.

+ 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. Replies: 8
    Last Post: 04-02-2016, 04:00 AM
  2. In Userform how can I change the background color of a Frame
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-13-2014, 12:27 PM
  3. Change cell background color based on another cells background color
    By Queo in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 4
    Last Post: 06-10-2014, 05:28 AM
  4. [SOLVED] Macro to change all cells with a certain background color in another background color
    By kevinvzandvoort in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-13-2012, 11:04 AM
  5. Can background color of frame change on userform by combobox selection on userfor
    By teacher_rob in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-12-2011, 05:47 PM
  6. how can I conditionally change font color, or background color?
    By MOHA in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-21-2006, 01:57 PM
  7. [SOLVED] change background row color with change of date in a cell
    By Urszula in forum Excel General
    Replies: 5
    Last Post: 05-17-2006, 03:00 AM

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