Setting the value held in a combobox

D

Duncs

I have a form with two unbound combo boxes, and several fields.

The idea of the form is that the user can select either of the two
combo's and the rest of the fields on the form will populate.

So, for example, if the user selects an entry from cboContractAccount,
the table will be searched and the fields populated with the values
associated with that ContractAccount. Alternatively, the user can
select an entry from cboSerialNum--if they don't know the
ContractAccount--and the fields will populate as appropriate.

However what I want to do is, if they select a ContractAccount from
cboContractAccount, I want cboSerialNum to populate with the serial
number for that record, and vice-versa. I've tried using:

.cboContractAccount.Value = ContractAcct

Where ContractAccount is the value retrieved from the database. In
debug mode, ContractAcct shows ''85002312542'
and .cboContractAccount.Value shows ''85002312542'. But, on the form,
cboContractAccount is blank.

Anyone advise?

TIA

Duncs
 
A

Arvin Meyer [MVP]

Use the column property of the combo. Say the serial number is in the 4th
column:

Me.cboContractAccount.Column(3)

The column index is zero based.
 
D

Duncs

Arvin,

Thanks for your suggestion. I've now changed the code as follows:

With Form
.cboContractAccount.Column(1) = ContractAcct
.cboSerial.Column(1) = SerialNum

But, when I run this, I am getting an error on the first assignment as
follows:

Err.number - 424
Err.Description - Object required

The code is in a 'DisplayRecord' routine that populates a form of
unbouond fields with the results of a query..

If I select an account number from the combo, when it enters the
routine, Form.cboContractAccount.Column(1) = 850034630569, which is
the value selected in the dropdown. The ContractAcct value passed is
850034630569. So, normal code execution is:

Select value
Retrieve data
Display data

However, with the two combos, I can't get them to show / retain the
value passed.

Help!!

Duncs
 
D

Duncs

I've tried.Column(1), I've tried .Text, I've tried everything I can
think of, but nothing seems to work.

I can't get a value assigned to the either of these combo controls.

Can someone help?

Many TIA

Duncs
 
D

Duncs

Ken, I've decided to re-think my idea. Perhaps what I'm trying to do
is too complex, or can be achieved an easier way.

I may however, re-visit this idea, so I'll be sure to shout out if I
get stuck!!

Many thanks for everyones help with this.

Duncs

Post the RowSource properties of the two combo boxes.

You need to make sure that whatever is the  BoundColumn of each combo box is
included as a column in the RowSource property of the other.  You can then,
in the AfterUpdate event procedure of each, assign the value of the relevant
column to the other control.

Ken Sheridan
Stafford, England




I've tried.Column(1), I've tried .Text, I've tried everything I can
think of, but nothing seems to work.
I can't get a value assigned to the either of these combo controls.
Can someone help?
Many TIA

[quoted text clipped - 73 lines]
- Show quoted text -
 

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