Auto-Selecting An Item In A Combo Box

M

Morris.C

How does one go about automatically selecting a value in a combo-box from
another form.
eg. Form1 opens Form2.
Form2 has a combo-box.
I want that combo-box to automatically select a value from Form1.

When I tried this in the OnLoad and GetFocus events:
Me!ComboBox101.Column(0) = Forms!Form1!Text1

I get this:
Run-time error 451
Property let procedure not defined and property get procedure did not
return an object.

I know Forms!Form1!Text1 is valid, I display it via "MsgBox Forms!Form1!
Text1". (I included this just for debugging purposes.)

What am I missing?!
 
R

Rick Brandt

Morris.C said:
How does one go about automatically selecting a value in a combo-box
from another form.
eg. Form1 opens Form2.
Form2 has a combo-box.
I want that combo-box to automatically select a value from Form1.

When I tried this in the OnLoad and GetFocus events:
Me!ComboBox101.Column(0) = Forms!Form1!Text1

You can't "set" a Column(n) in a ComboBox, you can only read them. You need to
set the Value property of the ComboBox.
 
M

Morris.C

You can't "set" a Column(n) in a ComboBox, you can only read them.
You need to set the Value property of the ComboBox.

But how can you set/select the Value of a column in the combo-box with
refering to that column?
(I should mention that the BoundColumn of the combo-box is 1, the value
coming from Form1 is found in Column 2. The sample of code I included was
wrong.)
 
R

Rick Brandt

Morris.C said:
But how can you set/select the Value of a column in the combo-box with
refering to that column?
(I should mention that the BoundColumn of the combo-box is 1, the
value coming from Form1 is found in Column 2. The sample of code I
included was wrong.)

You can only set the Value of the ComboBox which will be one of the choices in
its bound column (if LimitToList = True). After setting the Value for the bound
column then the other columns values will automatically correspond to those that
match the bound column value in the RowSource.

If your bound column is column 1 then you should be able to use...

Me!ComboBox101 = Forms!Form1!Text1
 
V

Van T. Dinh

You need to use the value in Forms!Form1!Text1 by some other means to find
the value that corresponds to the BoundColumn of the ComboBox and then set
the Value of the ComboBox with the found value.

For example, the BoundColumn is the RecordID and the value in the TextBox1
uniquely determine the Record, you can use DLookUp() to find the
corresponding RecordID and then set the Value of the ComboBox to the value
returned by DLookUp().

HTH
Van T. Dinh
MVP (Access)
 
M

Morris.C

You need to use the value in Forms!Form1!Text1 by some other means to
find the value that corresponds to the BoundColumn of the ComboBox and
then set the Value of the ComboBox with the found value.

For example, the BoundColumn is the RecordID and the value in the
TextBox1 uniquely determine the Record, you can use DLookUp() to find
the corresponding RecordID and then set the Value of the ComboBox to
the value returned by DLookUp().

HTH
Van T. Dinh
MVP (Access)

This is what I'm trying to do, but I've come up against a problem in
using Public variables to get the value from Form1 to Form2.
(see my next post.)
Thanks.
 

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