Trouble getting Default Value to work for combo box.

G

Guest

On an order details subform sfrOrderDetails I have a combo box
cboSetRebateID. The combo box works fine, but I want it to have (and display)
a default value (which can then be overridden if necessary) that is picked up
from a different control, txtDefaultRebateID on the same form. (The
txtDefaultRebateID value is set elsewhere and can differ from row to row; it
displays correctly.)

The Default Value property for the cboSetRebateID combo is entered as
=[Form]![sfrOrderDetails]![txtDefaultRebateID].

I’ve tried this with and without the equals sign, and I’ve made sure that
the control txtDefaultRebateID comes before cboSetRebateID in the tab order
sequence. But unless you make a selection the combo still just displays the
first value in its drop-down list, apparently ignoring the default property.

What could I be doing wrong?
 
R

Rick Brandt

David said:
On an order details subform sfrOrderDetails I have a combo box
cboSetRebateID. The combo box works fine, but I want it to have (and
display) a default value (which can then be overridden if necessary)
that is picked up from a different control, txtDefaultRebateID on the
same form. (The txtDefaultRebateID value is set elsewhere and can
differ from row to row; it displays correctly.)

The Default Value property for the cboSetRebateID combo is entered as
=[Form]![sfrOrderDetails]![txtDefaultRebateID].

I've tried this with and without the equals sign, and I've made sure
that the control txtDefaultRebateID comes before cboSetRebateID in
the tab order sequence. But unless you make a selection the combo
still just displays the first value in its drop-down list, apparently
ignoring the default property.

What could I be doing wrong?

You cannot use the value entered in one control as the default value of
another control because the default value is assigned as soon as the new
record is painted on the screen and the first control won't have a value in
it yet.

What you can do is copy the value entered in one control into a second
control in the first control's AfterUpdate event. The user would still be
free to change the second control afterwards to some other value, but if
they don't it will retain the same vvalue as the first control.
 
G

Guest

Thanks, Rick, for the explanation.

But I've now inserted this code where you suggest

Private Sub txtDefaultRebateID_AfterUpdate()
Me.cboSetRebateID = Me.txtDefaultRebateID
End Sub

and it still doesn't work. (Also deleted the Default Value property from the
combo box.) Could it be a problem that the text box (txtDefaultRebateID) is
automatically pulls a value from its underlying query when you go to a new
record on the subform? Does that count as an AfterUpdate situation?


Rick Brandt said:
David said:
On an order details subform sfrOrderDetails I have a combo box
cboSetRebateID. The combo box works fine, but I want it to have (and
display) a default value (which can then be overridden if necessary)
that is picked up from a different control, txtDefaultRebateID on the
same form. (The txtDefaultRebateID value is set elsewhere and can
differ from row to row; it displays correctly.)

The Default Value property for the cboSetRebateID combo is entered as
=[Form]![sfrOrderDetails]![txtDefaultRebateID].

I've tried this with and without the equals sign, and I've made sure
that the control txtDefaultRebateID comes before cboSetRebateID in
the tab order sequence. But unless you make a selection the combo
still just displays the first value in its drop-down list, apparently
ignoring the default property.

What could I be doing wrong?

You cannot use the value entered in one control as the default value of
another control because the default value is assigned as soon as the new
record is painted on the screen and the first control won't have a value in
it yet.

What you can do is copy the value entered in one control into a second
control in the first control's AfterUpdate event. The user would still be
free to change the second control afterwards to some other value, but if
they don't it will retain the same vvalue as the first control.
 
G

Guest

OK, I've now tried putting the code you suggested into the OnCurrent event
forthe form itself and that seems to have done the trick.

Thanks very much Rick for your help. I still feeling my way around event
properties and learning which ones to use.

Rick Brandt said:
David said:
On an order details subform sfrOrderDetails I have a combo box
cboSetRebateID. The combo box works fine, but I want it to have (and
display) a default value (which can then be overridden if necessary)
that is picked up from a different control, txtDefaultRebateID on the
same form. (The txtDefaultRebateID value is set elsewhere and can
differ from row to row; it displays correctly.)

The Default Value property for the cboSetRebateID combo is entered as
=[Form]![sfrOrderDetails]![txtDefaultRebateID].

I've tried this with and without the equals sign, and I've made sure
that the control txtDefaultRebateID comes before cboSetRebateID in
the tab order sequence. But unless you make a selection the combo
still just displays the first value in its drop-down list, apparently
ignoring the default property.

What could I be doing wrong?

You cannot use the value entered in one control as the default value of
another control because the default value is assigned as soon as the new
record is painted on the screen and the first control won't have a value in
it yet.

What you can do is copy the value entered in one control into a second
control in the first control's AfterUpdate event. The user would still be
free to change the second control afterwards to some other value, but if
they don't it will retain the same vvalue as the first control.
 

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