vba control/check comboboxes/textboxes are empty or not

DB73

Board Regular
Joined
Jun 7, 2022
Messages
59
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2010
  6. 2007
Platform
  1. Windows
  2. Mobile
  3. Web
Ive made a form with several comboboxes en textboxes
if i populate these i let a "command button"write the text/value to my dumpstats sheet.
but sometimes i forget to populate 1 of these boxes.

is it possible to add some vba to that command button, before it sends all value to the dumpstats sheet, too check if 1 or more of the boxes are empty and then color the empty red so i can fill them in.
after completion to let it write to my dumpstats sheet.

at first i made it just with a message boxes, thats shows "everyting filled in correctly ?", but that isnt actulay checking and sometime is just say yes , and then i get some faults.

thanks in advance
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
7,911
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Dave
if every cb is filled in then the data goes to my dumpstats sheet
my solution did not use any of the controls events - when you complete all required controls the function will return True to allow your code to submit the data.

If you want to change the backcolor from Red to whatever color as you enter data then you will need to do that in change event like that shown by @Anthony47 or you could create a common code for all events like this

place in Userform code page
VBA Code:
Sub SetBackColor(ByVal objControl As Control)
    With objControl
        .BackColor = IIf(Len(.Value) > 0, vbWhite, vbRed)
    End With
End Sub

which you call from each control change event
VBA Code:
Private Sub ComboBox1_Change()
    SetBackColor Me.ComboBox1
End Sub

Dave
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,186,627
Messages
5,958,873
Members
438,379
Latest member
impuce

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top