Select a new item in a combobox

  • Thread starter Thread starter Karen
  • Start date Start date
K

Karen

I have a combobox with two columns; the column(0) value is a NameID, the
column(1) is the Name itself. When I select 'New' in the combobox, I open
another form to capture the name of a new person. The other form opens as
acdialog.

After I close the Agent input form and return to the form with the combobox,
I want the new name selected in the combobox. I have done a requery so the
name is available but I can't, for the life of me, come up with how I
highlight my new name.
 
Hi Karen

Assuming the BoundColumn property of your combo is 1 (NameID) then all you
need to do is set the Value of the combo to the NameID of the new record you
have added.

Assuming you are opening the 'Agent Input' form in acDialog mode (to suspend
the code in your other form), then there are three ways to pass this value
back:

1. When the dialog form closes it can put the new ID value in a global
variable, which the first form's code picks up when it resumes.

2. When the dialog form closes, it 'pokes' the value straight into the
combobox:
Forms!FirstForm!cboSelectAgent = Me.NameID

3. Instead of closing, the dialog form makes itself invisible
(Me.Visible=False) and the calling code pulls the NameID value out of the
hidden form and then closes it.

I would use (2) if the input form is dedicated to this purpose, or (3) if it
is a general purpose form.
 
Graham,

I tried the second approach and the first approach and sure enough the name
is displayed in the combobox BUT when the name is normally selected in the
combobox, all other info attached to that person is displayed in some
following fields. So the problem is that although the name is displayed it
really hasn't been selected so the other info doesn't appear.

So, how do I display the name and ensure it is really selected so the other
info is recovered?
--
Karen
Graham Mandeno said:
Hi Karen

Assuming the BoundColumn property of your combo is 1 (NameID) then all you
need to do is set the Value of the combo to the NameID of the new record you
have added.

Assuming you are opening the 'Agent Input' form in acDialog mode (to suspend
the code in your other form), then there are three ways to pass this value
back:

1. When the dialog form closes it can put the new ID value in a global
variable, which the first form's code picks up when it resumes.

2. When the dialog form closes, it 'pokes' the value straight into the
combobox:
Forms!FirstForm!cboSelectAgent = Me.NameID

3. Instead of closing, the dialog form makes itself invisible
(Me.Visible=False) and the calling code pulls the NameID value out of the
hidden form and then closes it.

I would use (2) if the input form is dedicated to this purpose, or (3) if it
is a general purpose form.
 
Never mind, I got it working. Just forgot that even the other way I
actually 'put' values in the following fields depending upon the selection
in the combobox------duh!

--
Karen
Karen said:
Graham,

I tried the second approach and the first approach and sure enough the name
is displayed in the combobox BUT when the name is normally selected in the
combobox, all other info attached to that person is displayed in some
following fields. So the problem is that although the name is displayed it
really hasn't been selected so the other info doesn't appear.

So, how do I display the name and ensure it is really selected so the other
info is recovered?
--
Karen
Graham Mandeno said:
Hi Karen

Assuming the BoundColumn property of your combo is 1 (NameID) then all you
need to do is set the Value of the combo to the NameID of the new record you
have added.

Assuming you are opening the 'Agent Input' form in acDialog mode (to suspend
the code in your other form), then there are three ways to pass this value
back:

1. When the dialog form closes it can put the new ID value in a global
variable, which the first form's code picks up when it resumes.

2. When the dialog form closes, it 'pokes' the value straight into the
combobox:
Forms!FirstForm!cboSelectAgent = Me.NameID

3. Instead of closing, the dialog form makes itself invisible
(Me.Visible=False) and the calling code pulls the NameID value out of the
hidden form and then closes it.

I would use (2) if the input form is dedicated to this purpose, or (3)
if
it
is a general purpose form.

--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand

Karen said:
I have a combobox with two columns; the column(0) value is a NameID, the
column(1) is the Name itself. When I select 'New' in the combobox, I open
another form to capture the name of a new person. The other form
opens
 
Back
Top