Point to correct response

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a combo box on a form called Terminal_Nm. I have labels for Address,
City, St and ZipCode.

What I would like to have happen is when I select my Terminal from teh combo
box for all of the other info to be populated autmatically in the labels.

I am sure there is a question like this somewhere in here and I have seached
for a few days looking for something simialr but not luck.

Can anyone point me in the right direction or show me a sample of code?

Thanks
Tony
 
I have tried these out and I must be missing something.

My form is called frm_Dest
My combobox is called cbTermNm
My Lables are lblAdd, lblCt, lblSt, lblZip

When I select my Terminal Name from cbTermNm I want the labels to populate
the missing info from the table it reside in on the update.

For some reason I cannot get them to work. Either Monday is really getting
to me already or I just don't get it.

Thanks
 
First, are these actually labels or textboxes? Assuming labels, see if the
following example helps.

In the AfterUpdate event of the combo box:
Me.lblAdd.Caption = CStr(DLookup("[FieldName]", "[TableName]", "[FieldName
Associated with Combobox]=" & Me.cbTermNm))

Adjust the field name to match the field appropriate for the label being
filled. The syntax at the end assumes a number is returned by the combo box,
if it is text, adjust the line as follows:

Me.lblAdd.Caption = CStr(DLookup("[FieldName]", "[TableName]", "[FieldName
Associated with Combobox]='" & Me.cbTermNm & "'"))

The newsreader will probably wrap the lines due to their length, it should
be one line. If there are apostrophes in the value returned by the combo
box, another modification will need to be made, let me know if that is the
case. The value of the combo box is the value in the Bound Column of the
combo box when you've made a selection.

Another option is to add the other items to additional columns in the combo
box. You could set the width of those columns to zero to hide them, if you
wish. All visible columns will be displayed when the drop down is open, but
only the first visible column will be displayed once the selection is made.
You could then simple refer to the other columns in the combo box to get the
associated values.

Example:
Me.lblAdd.Caption = Me.cbTermNm.Column(1)

The column number above is zero based, so 0 is the first column, 1 is the
second, 2 is the third, etc. If the control is a textbox instead of a label,
you could set the Control Source of the textbox to point to the appropriate
column in the combo box and it will automatically update when the selection
is made, no code needed. If you want it to look like a label, you could play
with the formatting of the textbox (including the Locked and Enabled
properties) to make it look like a label.
 
Thanks. Just before your response I figured it out. Using on of the samples
you sent. I am just slow today I guess. I

Now my issue is I am trying to update the info from lbTermName to a field in
a called Orig in a table called Detail. And when I close the form or Move to
next record I want the data to popluate. But for some reason I can't get it
to follow through.



Wayne Morgan said:
First, are these actually labels or textboxes? Assuming labels, see if the
following example helps.

In the AfterUpdate event of the combo box:
Me.lblAdd.Caption = CStr(DLookup("[FieldName]", "[TableName]", "[FieldName
Associated with Combobox]=" & Me.cbTermNm))

Adjust the field name to match the field appropriate for the label being
filled. The syntax at the end assumes a number is returned by the combo box,
if it is text, adjust the line as follows:

Me.lblAdd.Caption = CStr(DLookup("[FieldName]", "[TableName]", "[FieldName
Associated with Combobox]='" & Me.cbTermNm & "'"))

The newsreader will probably wrap the lines due to their length, it should
be one line. If there are apostrophes in the value returned by the combo
box, another modification will need to be made, let me know if that is the
case. The value of the combo box is the value in the Bound Column of the
combo box when you've made a selection.

Another option is to add the other items to additional columns in the combo
box. You could set the width of those columns to zero to hide them, if you
wish. All visible columns will be displayed when the drop down is open, but
only the first visible column will be displayed once the selection is made.
You could then simple refer to the other columns in the combo box to get the
associated values.

Example:
Me.lblAdd.Caption = Me.cbTermNm.Column(1)

The column number above is zero based, so 0 is the first column, 1 is the
second, 2 is the third, etc. If the control is a textbox instead of a label,
you could set the Control Source of the textbox to point to the appropriate
column in the combo box and it will automatically update when the selection
is made, no code needed. If you want it to look like a label, you could play
with the formatting of the textbox (including the Locked and Enabled
properties) to make it look like a label.

--
Wayne Morgan
MS Access MVP


Tony said:
I have tried these out and I must be missing something.

My form is called frm_Dest
My combobox is called cbTermNm
My Lables are lblAdd, lblCt, lblSt, lblZip

When I select my Terminal Name from cbTermNm I want the labels to populate
the missing info from the table it reside in on the update.

For some reason I cannot get them to work. Either Monday is really
getting
to me already or I just don't get it.

Thanks
 
Again, the question is whether these are labels or textboxes. Also, by your
description, I'm not sure what exactly you're trying to do.

Just some general information though. You shouldn't need to keep copies of
multiple data from the record you select. For example, you shouldn't need to
keep a companies name, address, zip, phone, etc. in a second table. Instead,
the table that has this information should have a unique ID field for each
record. The only thing you should then need to keep in another table is the
value in this unique ID field. You would then link the tables on this common
field when you need the other information. The link will cause the tables to
"line up" so that you can get the correct information from the original
table when for each ID in the 2nd table.
 
Back
Top