Enter data in field 1 and autofill data in field 2

H

h2oEdge

I am making a table to order products. I would like to enter the product # in
said field and have the product description be placed in the product
description field. How do I do this? I have a Table with #'s in first field
and the description of product in the field next to it.
 
A

Al Camp

I would suggest a combo box (ex. cboProductNo) to select your ProductNo.
Place ProductNo in the first column and Description in the second.
Bind the combo to the ProductNo in your table, and using the AfterUpdate
event of cboProductNo...
Me.Description = cboProductNo.Column(1)
(combo columns are programatically referred to as 0 = first, 1 = second, 2 =
third, ... etc)
hth
Al Camp
Candia Computer Consulting - Candia NH
http://home.comcast.net/~cccsolutions
 
G

Graham R Seach

You can use DLookup to find the description, then other code to put it in
the textbox. For example:
Private Sub txtProductNo_AfterUpdate()
If Len(Me.txtProductNo) > 0 Then
Me.txtProductDescription = Nz(DLookup("[Description]", _
"tblProducts", "[ProductNo] = " & Me.txtProductNo), "")
End If
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
J

John Vinson

I am making a table to order products. I would like to enter the product # in
said field and have the product description be placed in the product
description field. How do I do this? I have a Table with #'s in first field
and the description of product in the field next to it.

Al and Graham have answered the direct question - but let me ask the
question that your question raises:

Do you really want to store the Description redundantly in your Orders
table? I'd say no.

The only reason you might want to COPY a field from the Product table
to the Order table is if you need to store the value of the field *at
the time of the order*, so that if it's later changed in the Product
table the stored value remains unchanged. This makes sense for a
price, which may change; but for a description, I'd suggest that you
want to leave the field ONLY in the Product table, and display or
print it using a Query linking from the ProductID.

John W. Vinson[MVP]
 
G

Graham R Seach

I had the feelng that the OP simply wanted to display the description in a
textbox (mis-termed as 'field').

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
A

Al Camp

Ditto...
Al Camp

John Vinson said:
Al and Graham have answered the direct question - but let me ask the
question that your question raises:

Do you really want to store the Description redundantly in your Orders
table? I'd say no.

The only reason you might want to COPY a field from the Product table
to the Order table is if you need to store the value of the field *at
the time of the order*, so that if it's later changed in the Product
table the stored value remains unchanged. This makes sense for a
price, which may change; but for a description, I'd suggest that you
want to leave the field ONLY in the Product table, and display or
print it using a Query linking from the ProductID.

John W. Vinson[MVP]
 
J

John Vinson

I had the feelng that the OP simply wanted to display the description in a
textbox (mis-termed as 'field').

Sure... but wouldn't just setting the Control Source of the textbox to
=combobox.Column(n) accomplish that just as well, with no code? Your
solution is exactly what's needed for a *bound* textbox, which is
indeed sometimes useful.

John W. Vinson[MVP]
 
G

Graham R Seach

Yeah, that's a good idea. I didn't think of that!

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Top