G
Guest
I have two questions about writing more efficient code:
1. Whenever I have combo boxes on a form, I almost always add
Me.<FieldName>.Dropdown to the On Enter event for each. This can get tedious
if I have many combo boxes. Is there a more efficient way to handle this?
(Like, maybe tag each combo box and write code that says to drop down every
tagged control upon enter. Or, use a function somehow that automatically
drops down any combox box when it's entered?
2. If a user selects “Yes†from a combo box, I would like to enable a
collection of controls that are related to that Yes/No question. (The
controls could be checkboxes, text boxes, or both). If the user selects “No,â€
I would like to disable these controls. I always end up putting something
like this in the After Update event for the combo box:
If Me.Bruises.Value = "Yes" Then
Me.Hands.Enabled = True
Me.Hands.Locked = False
Me.Face.Enabled = True
Me.Face.Locked = False
Me.Neck.Enabled = True
Me.Neck.Locked = False
Else
Me.Hands.Enabled = False
Me.Hands.Locked = False
Me.Face.Enabled = False
Me.Face.Locked = False
Me.Neck.Enabled = False
Me.Neck.Locked = False
End If
This can get tedious if there are many controls related to the combo box, or
if I need to repeat this process for subsequent Yes/No questions. Is there a
more efficient way to handle this? Like, somehow assign a series of controls
as a collection, and then refer to that collection?
Thanks!
Kurt
1. Whenever I have combo boxes on a form, I almost always add
Me.<FieldName>.Dropdown to the On Enter event for each. This can get tedious
if I have many combo boxes. Is there a more efficient way to handle this?
(Like, maybe tag each combo box and write code that says to drop down every
tagged control upon enter. Or, use a function somehow that automatically
drops down any combox box when it's entered?
2. If a user selects “Yes†from a combo box, I would like to enable a
collection of controls that are related to that Yes/No question. (The
controls could be checkboxes, text boxes, or both). If the user selects “No,â€
I would like to disable these controls. I always end up putting something
like this in the After Update event for the combo box:
If Me.Bruises.Value = "Yes" Then
Me.Hands.Enabled = True
Me.Hands.Locked = False
Me.Face.Enabled = True
Me.Face.Locked = False
Me.Neck.Enabled = True
Me.Neck.Locked = False
Else
Me.Hands.Enabled = False
Me.Hands.Locked = False
Me.Face.Enabled = False
Me.Face.Locked = False
Me.Neck.Enabled = False
Me.Neck.Locked = False
End If
This can get tedious if there are many controls related to the combo box, or
if I need to repeat this process for subsequent Yes/No questions. Is there a
more efficient way to handle this? Like, somehow assign a series of controls
as a collection, and then refer to that collection?
Thanks!
Kurt