I have been teaching myself VBA to create a data entry form for entering my company's products into a spreadsheet. The form includes 30 textboxes where the user can enter the specific brand’s possible colors, and a checkbox for each to indicate whether that color should be used for a specific product (e.g., Product A comes in Red, Blue and Green, but Product B only comes in Red and Green). Ideally, this form allows the user not to have to reenter the colors for every product, since they are all drawn from the same collection of possibilities.
I am trying to create a “Select All Colors” feature that will only check boxes where the user has entered a color. Here is a sample of what I have right now:
When I test it using message boxes, the state of varChkColor(intM) shows up as True when varTxtColor(intM) isn’t blank, so that part is somewhat working, but the checkboxes never appear checked on the form and my error-catching message of “You haven’t selected a color” pops up when I try to submit. I’ve tried changing to varChkColor(intM).value = true, but the debugger says I need an object.
I know this must be related to the fact that you can’t make an array of controls. I’ve used this kind of workaround elsewhere in the form:
But this only lets me select *all* color checkboxes (Tag 4), even when no color has been entered in the corresponding text box. Is there any way around this? Thanks in advance for any advice.
I am trying to create a “Select All Colors” feature that will only check boxes where the user has entered a color. Here is a sample of what I have right now:
Code:
Dim varTxtColor(3) As Variant
varTxtColor(0) = txtColor0
varTxtColor(1) = txtColor1
varTxtColor(2) = txtColor2
Dim varChkColor(3) As Variant
varChkColor(0) = chkColor0
varChkColor(1) = chkColor1
varChkColor(2) = chkColor2
Dim intM As Integer
For intM = 0 To 2
If Not varTxtColor(intM) = "" Then
varChkColor(intM) = True
End If
Next
When I test it using message boxes, the state of varChkColor(intM) shows up as True when varTxtColor(intM) isn’t blank, so that part is somewhat working, but the checkboxes never appear checked on the form and my error-catching message of “You haven’t selected a color” pops up when I try to submit. I’ve tried changing to varChkColor(intM).value = true, but the debugger says I need an object.
I know this must be related to the fact that you can’t make an array of controls. I’ve used this kind of workaround elsewhere in the form:
Code:
For Each ctrl In frmTPMSDataEntry.Controls
If ctrl.Tag = "4" Then
ctrl.Value = True
End If
Next
But this only lets me select *all* color checkboxes (Tag 4), even when no color has been entered in the corresponding text box. Is there any way around this? Thanks in advance for any advice.