Select to view content in your preferred language

How do set the ReadOnly attribute of a combo box in vbs?

1156
1
Jump to solution
04-25-2012 08:58 AM
MikeRadko
Occasional Contributor
I have a checkbox control that when activated (value=true) would change a combo box from read-only to editable (readonly=false).  I am initiating this event through the OnClick event of the Editform checkbox (chkMort).  My code thus far is simply:
----
Sub Mort
Dim MortPg

Set MortPg = objEditForm.Pages("page2")

If MortPg.Controls("chkMort").Value = True Then
MortPg.Controls("cboMort").ReadOnly = False
Else
MortPg.Controls("cboMort").ReadOnly = True
End If
End Sub
----

But I am obviously getting the syntax wrong with the ReadOnly attribute. I cannot find an example anywhere on how to make this syntax correct, can anyone help me?

Thanks.
-mike
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
TimHopper
Frequent Contributor
Mike,

Without testing myself...

The Control object does not have a property of "ReadOnly".  The property you would be looking for is "Enabled".  Controls with Enabled = True can be edited, those with Enabled = False will be grayed out.

Still, you'd need some additional changes besides this.  I don't believe that while in a checkbox control you can get to the ThisEvent.Object.Pages().Control() property.  You've got to get back out to it's parent.

I would try something like this during the onclick event of the checkbox control:

Dim myvalue myvalue = ThisEvent.Object.Value  If myvalue = "True" Then ThisEvent.Object.Parent.Parent.Pages("PAGE1").Controls("domComboBox").Enabled = True


You would probably need to set the default value for the checkbox to "False" so that it opens unchecked.  Also, if you wanted to enable the ComboBox with a checkbox value of True, you should probably set the state of the combobox to be read-only by default.

View solution in original post

0 Kudos
1 Reply
TimHopper
Frequent Contributor
Mike,

Without testing myself...

The Control object does not have a property of "ReadOnly".  The property you would be looking for is "Enabled".  Controls with Enabled = True can be edited, those with Enabled = False will be grayed out.

Still, you'd need some additional changes besides this.  I don't believe that while in a checkbox control you can get to the ThisEvent.Object.Pages().Control() property.  You've got to get back out to it's parent.

I would try something like this during the onclick event of the checkbox control:

Dim myvalue myvalue = ThisEvent.Object.Value  If myvalue = "True" Then ThisEvent.Object.Parent.Parent.Pages("PAGE1").Controls("domComboBox").Enabled = True


You would probably need to set the default value for the checkbox to "False" so that it opens unchecked.  Also, if you wanted to enable the ComboBox with a checkbox value of True, you should probably set the state of the combobox to be read-only by default.
0 Kudos