Loop to disable object

N

nxqviet

Hi all,

I have a simple Loop question. On the same form, I have a combo box and
a few check boxes. I want all the check boxes to be disabled untill
user select an item from the combo box. If the combo box become Null
again, all the check box should return to disabled (enabled = false).

I tried Do While ... Loop. But it only disable the check box upon load
form. Can some one help me with his loop? and where should I put this
loop so that it will run continuously.

Thanks


V_
 
B

Brendan Reynolds

The example below shows two ways to do it. The first method depends on the
controls having names endingn with sequential numbers - 'chkTest1',
'chkTest2', and 'chkTest3' in this example. The second method uses a
single-page tab control with the 'Style' property set to 'None' as a
container for the check boxes. Just enable/disable the tab control to
enable/disable all the controls contained within it.

With a bound form, you'll need to add this code both to the AfterUpdate
event procedure of the combo box, as shown in the example, and also to the
Current event procedure of the form.

Private Sub cboTest_AfterUpdate()

Dim lngCounter As Long

For lngCounter = 1 To 3
Me.Controls("chkTest" & lngCounter).Enabled = Not IsNull(Me.cboTest)
Next lngCounter

Me.tabTest.Enabled = Not IsNull(Me.cboTest)

End Sub
 
A

Adam Thwaites

You don't need a loop for this solution, I would just use an AfterUpdate
command for the combobox:

Private Sub cboComboBox_AfterUpdate()
if len(nz(cboComboBox,"")) > 0 then
chkCheck1.enabled = true
else
chkCheck1.enabled = false
chkCheck1.value = ""
end if
End Sub

Also you can have the Change command covered so the combobox doesn't have to
lose focus to update the check boxes:

Private Sub cboComboBox_Change()
if len(nz(cboComboBox.text,"")) > 0 then
chkCheck1.enabled = true
else
chkCheck1.enabled = false
chkCheck1.value = ""
end if
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top