We help IT Professionals succeed at work.

Set Combo box default based on contents of a text box

taborrg
taborrg asked
on
Hi,

I'm trying to set the default value for a combo box based on the content of a text box

I have the default value field set to:
=[txtContractorFullName].[Text]

The combo box says #Error.

Thanks,

Rick

Comment
Watch Question

Jeffrey CoachmanMIS Liason
Most Valuable Expert 2012

Commented:
A "Default value" is defined as the value that is entered when a *New record* is created.
(See the help files on the Default Value property of a combobox)

This is not the same as simply setting some text to display by default in a combobox.

Can you first take a step back and explain in detail your design here and what your ultimate goal is?

(why the text in a combobox need to change based on a textbox value...)
(Why this value is not in the comboboxes row source...?)
...etc

JeffCoachman
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
Default Value only applies on a New Record. And you need to set the Bound column of the combo box.

What is the Row Source of the combo box?
How many columns?

mx

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
Also, when ... exactly are you wanting or expecting to set the Default Value ?
It would at least have to be after something was entered into the txtContractorFullName text box.

mx
Rick,

Try to put this on the Control Source Property of your combobox.

=Forms![NameOfYourForm]![txtContractorFullName]

Sincerely,
Ed

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
But why ... would you want a Combo to have that as a control source? I can't think of an instance where a Combo is going to be a calculated control ...?

mx

Author

Commented:
It's set to 4 rows.  I have the row source as:

SELECT ContractorLastName & ",  " & ContractorFirstName AS ContractorName, ContractorID, ContractorLastName, ContractorFirstName FROM RTABOR_T_Contractors ORDER BY ContractorLastName;

Which gives a nice "LastName, FirstName" for column 0.

On the attached image you can see it.  The form loads with the combo box empty, and two textboxes with name fields filled in.

I would like to not have the two separate name field textboxes, and have the selected (from the parent form) contractor name appear in the combo box.

I hope these two images help to explain it.

Thanks.


 ComboBoxOnLoad ComboBoxOnLoadComboBoxAfter-a-selection.bmp

Author

Commented:
It works!

Thanks.

Author

Commented:
Hey Ed,

That worked, but then the combo box wouldn't allow choosing.  It locked up.  So I removed that and put this in the form's On Load.

Me.cboContractors.Value = [Forms]![frmContractorAssignmentEdit]![txtContractorFullName]

Now it works fine.

Thanks again!
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
"That worked, but then the combo box wouldn't allow choosing.  It locked up.  So I removed that and put this in the form's On Load."

Like I said :-)

So, in reality, the Accepted Answer does not really work ...

mx

Author

Commented:
Good point.  And I was ready to jump back on the thread when I saw the combo box was locked up.

But it got me close enough to make it the rest of the way on my own, so I'm greatful.

I really appreciate all the help from the EE experts, I wouldn't have been able to do this job without your help.