Hello,
I have a continuous form bound to a table. I have one control on the form, a combobox. When I select a new value in the form's combobox (which is bound to a field in the table) I would like to update a "hidden" field on the table, in the same record. By "hidden" I mean not visibly bound to any control on the form.
So for example, my bound table has two fields, and is empty to begin with:
Fruit Size
---- ----
I have another table (not bound to any form) like so:
Fruit Color Size Seedless
---- ---- --- --------
Apple Red M N
Pear Grn M N
Grape Grn S Y
If I select "Apple" from the form's combobox, I would like the bound table to update to:
Fruit Size
---- ----
Apple M
I have no problem populating the "Fruit" field, since it is bound directly to the combobox, but am having a problem also populating the "Size" field, because it is not bound to any control.
I have populated the combobox's Row Source with a query having 2 columns, Fruit and Size, Fruit being visible and Size being hidden. I'm trying to use the Size column's value to populate a record in the table's Size field. I've taken this approach, and had some luck, but the code seems to trip itself up sometimes and is not consistently working (sometimes Size is missing, sometimes it's there):
After a few goes, my table might look like:
Fruit Size
---- ----
Apple
Grape S
Pear
Here is the code (I'm using the AfterUpdate event on the combobox):
Private Sub cmbFruits_AfterUpdate()
Dim rs As Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst "[Fruit] = '" & Me![cmbFruits] & "'"
If Not rs.EOF Then
rs.Edit
rs.Fields("SIZE").Value = Me.cmbManagers.Column(1)
rs.Update
Set Me.Recordset = rs
End If
Set rs = Nothing
End Sub
I'm not quite sure about the placement of the Edit and Update methods, and should I be setting one recordset to another?
Hope I haven't made this confusing...
Any help would be appreciated!
Thanks,
Scott
I have a continuous form bound to a table. I have one control on the form, a combobox. When I select a new value in the form's combobox (which is bound to a field in the table) I would like to update a "hidden" field on the table, in the same record. By "hidden" I mean not visibly bound to any control on the form.
So for example, my bound table has two fields, and is empty to begin with:
Fruit Size
---- ----
I have another table (not bound to any form) like so:
Fruit Color Size Seedless
---- ---- --- --------
Apple Red M N
Pear Grn M N
Grape Grn S Y
If I select "Apple" from the form's combobox, I would like the bound table to update to:
Fruit Size
---- ----
Apple M
I have no problem populating the "Fruit" field, since it is bound directly to the combobox, but am having a problem also populating the "Size" field, because it is not bound to any control.
I have populated the combobox's Row Source with a query having 2 columns, Fruit and Size, Fruit being visible and Size being hidden. I'm trying to use the Size column's value to populate a record in the table's Size field. I've taken this approach, and had some luck, but the code seems to trip itself up sometimes and is not consistently working (sometimes Size is missing, sometimes it's there):
After a few goes, my table might look like:
Fruit Size
---- ----
Apple
Grape S
Pear
Here is the code (I'm using the AfterUpdate event on the combobox):
Private Sub cmbFruits_AfterUpdate()
Dim rs As Recordset
Set rs = Me.Recordset.Clone
rs.FindFirst "[Fruit] = '" & Me![cmbFruits] & "'"
If Not rs.EOF Then
rs.Edit
rs.Fields("SIZE").Value = Me.cmbManagers.Column(1)
rs.Update
Set Me.Recordset = rs
End If
Set rs = Nothing
End Sub
I'm not quite sure about the placement of the Edit and Update methods, and should I be setting one recordset to another?
Hope I haven't made this confusing...
Any help would be appreciated!
Thanks,
Scott