2 questions on combobox control

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

1. I have a combo box on a subform that is displayed in contiuous form mode
(i.e., more than one record is displayed).

When I set a value in the parent form, I need to check all of the records on
the subform and if the value in the combobox is NULL, I need to change it to
the value set on the parent.

I can reference the combo box of the first record on the subform as:

If IsNull(Me.f_check_SUB.Form![cboInvestment].Value) Then
do something...

But how can I check each record in the subform and take the necessary
action?

I think I need to loop through all of the records, checking each combobox as
I go. But I cannot find an syntax example of how to reference individual
records. Does anyone have some sample code of how to do this?

2. When I reference a combo box as "![cboInvestment].Value" I get the value
of the ID in the bound column by default.

But what if I have 3 values associated with the combobox: the hidden ID, the
displayed value, and another hidden value.

How can I reference the other 2 values (the displayed value and the second
hidden value)?

For example, if the combobox is populated with a value list as
"1;California;West" how do I write code to return the values of "California"
and "West?"
 
Dave said:
1. I have a combo box on a subform that is displayed in contiuous form mode
(i.e., more than one record is displayed).

When I set a value in the parent form, I need to check all of the records on
the subform and if the value in the combobox is NULL, I need to change it to
the value set on the parent.

I can reference the combo box of the first record on the subform as:

If IsNull(Me.f_check_SUB.Form![cboInvestment].Value) Then
do something...

But how can I check each record in the subform and take the necessary
action?

I think I need to loop through all of the records, checking each combobox as
I go. But I cannot find an syntax example of how to reference individual
records. Does anyone have some sample code of how to do this?

Here's some air code for a button's Click event or if you're
feeling confident about your users never making a mistake,
the AftreUpdate event of the main form's text box for the
value. I'll name this text box txtValue:

With Me.subformcontrol.Form.RecordsetClone
.MoveFirst
Do Until .EOF
If IsNull(!comboboxboundfield) Then
!comboboxboundfield = Me.txtValue
End If
.MoveNext
Loop
End With

Note that this refers to the field bound to the combo box,
not to the combo box itself.

2. When I reference a combo box as "![cboInvestment].Value" I get the value
of the ID in the bound column by default.

But what if I have 3 values associated with the combobox: the hidden ID, the
displayed value, and another hidden value.

How can I reference the other 2 values (the displayed value and the second
hidden value)?

For example, if the combobox is populated with a value list as
"1;California;West" how do I write code to return the values of "California"
and "West?"

You can use the Column property to get any column (and any
row) of a combo box's RowSource. For example:

Me.combobox.Column(0) will get the 1
Me.combobox.Column(1) will get the "California"
Me.combobox.Column(2) will get the "West"
 
Thank you Marsh, that was very helpful information.



Marshall Barton said:
Dave said:
1. I have a combo box on a subform that is displayed in contiuous form mode
(i.e., more than one record is displayed).

When I set a value in the parent form, I need to check all of the records on
the subform and if the value in the combobox is NULL, I need to change it to
the value set on the parent.

I can reference the combo box of the first record on the subform as:

If IsNull(Me.f_check_SUB.Form![cboInvestment].Value) Then
do something...

But how can I check each record in the subform and take the necessary
action?

I think I need to loop through all of the records, checking each combobox as
I go. But I cannot find an syntax example of how to reference individual
records. Does anyone have some sample code of how to do this?

Here's some air code for a button's Click event or if you're
feeling confident about your users never making a mistake,
the AftreUpdate event of the main form's text box for the
value. I'll name this text box txtValue:

With Me.subformcontrol.Form.RecordsetClone
.MoveFirst
Do Until .EOF
If IsNull(!comboboxboundfield) Then
!comboboxboundfield = Me.txtValue
End If
.MoveNext
Loop
End With

Note that this refers to the field bound to the combo box,
not to the combo box itself.

2. When I reference a combo box as "![cboInvestment].Value" I get the value
of the ID in the bound column by default.

But what if I have 3 values associated with the combobox: the hidden ID, the
displayed value, and another hidden value.

How can I reference the other 2 values (the displayed value and the second
hidden value)?

For example, if the combobox is populated with a value list as
"1;California;West" how do I write code to return the values of "California"
and "West?"

You can use the Column property to get any column (and any
row) of a combo box's RowSource. For example:

Me.combobox.Column(0) will get the 1
Me.combobox.Column(1) will get the "California"
Me.combobox.Column(2) will get the "West"
 
Back
Top