visible Invisible text and check boxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that has a couple of hundred fields, what I would like to do
is....

I have two areas of input (text boxes) each containing 3 boxes

if there is input in one of the boxes in one group, I would like to "grey
out" the other group and visa versa, also if I remove the text from the one
group to return the groups to thier original state.

I also have check boxes that I would like to do the same thing with.

Thank you in advance,
Paul M
 
okay, here's a solution. the code's not too bad, but the explanation will be
a bit lengthy, so sit back and get comfortable...

first, identify two "paired" groups of controls that you want to manipulate
in tandem. in the first group of controls, set each control's Tag property
to "A" (without the quote marks). in the second group, set each control's
Tag property to "B" (again sans quote marks).

paste the following custom procedure into the form's module, as

Private Sub ResetGroup(ByVal strCurGroup As String, ByVal str As String)

Dim ctrl As Control, bln As Boolean
bln = True

For Each ctrl In Me.Controls
If ctrl.Tag = strCurGroup Then
If TypeOf ctrl Is CheckBox Then
If ctrl = True Then
bln = False
Exit For
End If
ElseIf Not IsNull(ctrl) Then
bln = False
Exit For
End If
End If
Next ctrl

For Each ctrl In Me.Controls
If ctrl.Tag = str Then
ctrl.Enabled = bln
End If
Next ctrl

End Sub

in the AfterUpdate event procedure of each control in group A, add the
following code, as

ResetGroup Me.Tag, "B"

in the AfterUpdate event procedure of each control in group B, add the
following code, as

ResetGroup Me.Tag, "A"

in the form's Current event procedure, add the following code, as

Dim colGroups As New Collection

colGroups.Add Array("A", "B")
colGroups.Add Array("B", "A")

Dim var As Variant

For Each var In colGroups
ResetGroup var(0), var(1)
Next var

notice how the code directly above adds two elements to the collection, for
the "paired groups": Array("A", "B") AND Array("B", "A").

now identify the next two "paired groups"; let's call them "C" and "D". set
the Tag property of each control in the first group to C, and the Tag
property of each control in the second group to D. you'll need to add code
to the form's Current event, to add two *additional* elements to the
collection, immediately below the first two elements, as

colGroups.Add Array("C", "D")
colGroups.Add Array("D", "C")


in the AfterUpdate event procedure of each control in group C, add the
following code, as

ResetGroup Me.Tag, "D"

in the AfterUpdate event procedure of each control in group D, add the
following code, as

ResetGroup Me.Tag, "C"

continue identifying each group you want to manipulate in tandem, and
setting them up as explained above. note that a group can be all textboxes,
all checkboxes, or a combination of the two (the code should work on
combobox controls too - though i didn't test it specifically - and *maybe*
on option group controls - didn't test that either.)

also note that the Tag value can more than one letter, if you want - such as
"Group1" and "Group2", or whatever - just make sure you reference the
correct Tag value throughout the code.

hth
 
Paul said:
I have a form that has a couple of hundred fields, what I would like to do
is....

I have two areas of input (text boxes) each containing 3 boxes

if there is input in one of the boxes in one group, I would like to "grey
out" the other group and visa versa, also if I remove the text from the one
group to return the groups to thier original state.

I also have check boxes that I would like to do the same thing with.


Sounds like a very busy form.

Whatever. Here's an idea, set the Tag property of the
controls you want to disable to a grouping indentifier
string. E.g. area 1 is group A, area 2 is group B, some
check boxes are group C, etc. If something is in more that
one group just put both group letters in the Tag property.
Be sure to avoid doing this for controls that do not have
the Enabled property.

Next create a sub to enable/disable all the controls in a
group:

Sub SetEnable(strGrp As String, bolOnOff As Boolean)
Dim ctl As Control

For Each ctl In Me.Controls
If ctl.Tag Like "*" & strGrp & "*" Then
ctl.Enabled = bolOnOff
End If
Next ctl
End Sub

Then use your text box's AfterUpdate event to call the
procedure. E.g. Area A's text box could be:

If IsNull(Me.txtbox1) Then
SetEnable "B', True
Else
SetEnable "B", False
End If

or, more briefly:

SetEnable "B', IsNull(Me.txtbox1)

With similar code for area 2's text box and your important
check boxes.
 
oops! i made an error in the original code that didn't show up in my
testing; so here's a correction to the posted code. the original code was:
in the AfterUpdate event procedure of each control in group A, add the
following code, as

ResetGroup Me.Tag, "B"

in the AfterUpdate event procedure of each control in group B, add the
following code, as

ResetGroup Me.Tag, "A"

in each instance where you add code to a control's AfterUpdate event,
"Me.Tag" must be replaced with "Screen.ActiveControl.Tag", as

in the AfterUpdate event procedure of each control in group A, add the
following code, as

ResetGroup Screen.ActiveControl.Tag, "B"

in the AfterUpdate event procedure of each control in group B, add the
following code, as

ResetGroup Screen.ActiveControl.Tag, "A"

otherwise, the code is fine.

hth
 
Back
Top