Default value for combo boxes

G

Guest

hi
I have 2 comboboxes (cbxReg and cbxArea) on my form (frmReg). cbxReg gets
its values from a query, and I set its Default Value property
=[cbxReg].[ItemData](0). Works great.

Now, the 2nd combobox gets its Row Source from the AfterUpdate event of the
1st combobox:
'to ensure cbxArea CLEARED if cbxReg changed
Me!cbxArea.Value = Null
'now reset Row Source of cbxArea
Me!cbxArea.RowSource = "SELECT qryReg.RegID,qryReg.RegName FROM qryReg
WHERE RegID= " &
Me!cbxReg.Column(0) & ";"
Forms!frmReg.requery
Me!cbxArea.SetFocus

My problem is in how to set the 2nd comboboxes default value. When the form
opens, I'd like its default value to be =[cbxArea].[ItemData](0), but only
AFTER its RowSource is set by the 1st combobox. Any clues how I can get this
to work?

much thanks
 
M

Marshall Barton

Sophie said:
I have 2 comboboxes (cbxReg and cbxArea) on my form (frmReg). cbxReg gets
its values from a query, and I set its Default Value property
=[cbxReg].[ItemData](0). Works great.

Now, the 2nd combobox gets its Row Source from the AfterUpdate event of the
1st combobox:
'to ensure cbxArea CLEARED if cbxReg changed
Me!cbxArea.Value = Null
'now reset Row Source of cbxArea
Me!cbxArea.RowSource = "SELECT qryReg.RegID,qryReg.RegName FROM qryReg
WHERE RegID= " &
Me!cbxReg.Column(0) & ";"
Forms!frmReg.requery
Me!cbxArea.SetFocus

My problem is in how to set the 2nd comboboxes default value. When the form
opens, I'd like its default value to be =[cbxArea].[ItemData](0), but only
AFTER its RowSource is set by the 1st combobox. Any clues how I can get this
to work?


Assuming that both combo boxes are bound.

I think you are struggling with the fact that the
DefaultValue property was applied at the time of the first
keystroke (or list selection) on the new record. Any
changes to the DefaultValue will not be applied until the
next new record is dirtied.

Since selecting something in the first combo box dirties the
new record, it won't do any harm to just set the second
combo box's Value property in the first combo box's
AfterUpdate event. Actually, you should do something like
that anyway even if it's just to invalidate any previous
value for the second combo box. You don't want it to be out
of sync with its new RowSource.
 

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