Populate another field using Combo Box

G

Guest

I have a Form and within the Form there is a Subform which contains a Combo
Box (Products) which is bound to a table. The Combo Box has two columns –
Product and Stock Code. Each time a Product is selected the Stock Code text
box is automatically populated. However, the Stock Code does not store the
value in the table and only displays on the Form. It is because the Control
Source for Stock Code is:

=[cboProducts].[Column](1)


And for the Product Combo Box the code is:

Private Sub Product_AfterUpdate()
Me.txtStockCode = Me.cboProducts.Column(1)
End Sub

Is there any way I can get this to store the Stock Code in the table.
 
A

Alessandro Baraldi

Kirt84 ha scritto:
I have a Form and within the Form there is a Subform which contains a Combo
Box (Products) which is bound to a table. The Combo Box has two columns -
Product and Stock Code. Each time a Product is selected the Stock Code text
box is automatically populated. However, the Stock Code does not store the
value in the table and only displays on the Form. It is because the Control
Source for Stock Code is:

=[cboProducts].[Column](1)


And for the Product Combo Box the code is:

Private Sub Product_AfterUpdate()
Me.txtStockCode = Me.cboProducts.Column(1)
End Sub

Is there any way I can get this to store the Stock Code in the table.

Action query on AfterUpdate Event...?

UPDATE T1
SET Field1=NewValue
WHERE Field1=OldValue

@Alex
 
G

Guest

Not sure what you mean by this - Please could you explain this again as I am
still new to Access.
--
Thank you for your help


Alessandro Baraldi said:
Kirt84 ha scritto:
I have a Form and within the Form there is a Subform which contains a Combo
Box (Products) which is bound to a table. The Combo Box has two columns -
Product and Stock Code. Each time a Product is selected the Stock Code text
box is automatically populated. However, the Stock Code does not store the
value in the table and only displays on the Form. It is because the Control
Source for Stock Code is:

=[cboProducts].[Column](1)


And for the Product Combo Box the code is:

Private Sub Product_AfterUpdate()
Me.txtStockCode = Me.cboProducts.Column(1)
End Sub

Is there any way I can get this to store the Stock Code in the table.

Action query on AfterUpdate Event...?

UPDATE T1
SET Field1=NewValue
WHERE Field1=OldValue

@Alex
 
B

BruceM

Did you not like the answer to this same question you posted yesterday?

Kirt84 said:
Not sure what you mean by this - Please could you explain this again as I
am
still new to Access.
--
Thank you for your help


Alessandro Baraldi said:
Kirt84 ha scritto:
I have a Form and within the Form there is a Subform which contains a
Combo
Box (Products) which is bound to a table. The Combo Box has two
columns -
Product and Stock Code. Each time a Product is selected the Stock Code
text
box is automatically populated. However, the Stock Code does not store
the
value in the table and only displays on the Form. It is because the
Control
Source for Stock Code is:

=[cboProducts].[Column](1)


And for the Product Combo Box the code is:

Private Sub Product_AfterUpdate()
Me.txtStockCode = Me.cboProducts.Column(1)
End Sub

Is there any way I can get this to store the Stock Code in the table.

Action query on AfterUpdate Event...?

UPDATE T1
SET Field1=NewValue
WHERE Field1=OldValue

@Alex
 
A

Alessandro Baraldi

Kirt84 ha scritto:
Not sure what you mean by this - Please could you explain this again as I am
still new to Access.
--
Thank you for your help


Alessandro Baraldi said:
Kirt84 ha scritto:
I have a Form and within the Form there is a Subform which contains a Combo
Box (Products) which is bound to a table. The Combo Box has two columns -
Product and Stock Code. Each time a Product is selected the Stock Code text
box is automatically populated. However, the Stock Code does not store the
value in the table and only displays on the Form. It is because the Control
Source for Stock Code is:

=[cboProducts].[Column](1)


And for the Product Combo Box the code is:

Private Sub Product_AfterUpdate()
Me.txtStockCode = Me.cboProducts.Column(1)
End Sub

Is there any way I can get this to store the Stock Code in the table.

Action query on AfterUpdate Event...?

UPDATE T1
SET Field1=NewValue
WHERE Field1=OldValue

@Alex


You ask about a different way to Update the Record Value....?

This is one:

Private Sub Product_AfterUpdate()
Dim StrSQL as string
' In this case i presume FieltType(Numeric), if is Text
' you need to insert string condition formatting
strSQL="UPDATE T1 " & _
"SET Field1=" & Me.cboProducts.Column(1) & " " &_
"WHERE Field1=" & OldValue
' you need to get the OldValue or the PK reference to Point to the
exactly Record
currentdb.execute strSQL,dbfailionerror
End Sub

Bye
@Alex
 
G

Guest

Hi Bruce

I wasn't sure what you meant as I am still new to Access. If you have a
solution to this probolem please could you expalin it in a easier way. It
would be much appreciated......
--
Thank you for your help


BruceM said:
Did you not like the answer to this same question you posted yesterday?

Kirt84 said:
Not sure what you mean by this - Please could you explain this again as I
am
still new to Access.
--
Thank you for your help


Alessandro Baraldi said:
Kirt84 ha scritto:

I have a Form and within the Form there is a Subform which contains a
Combo
Box (Products) which is bound to a table. The Combo Box has two
columns -
Product and Stock Code. Each time a Product is selected the Stock Code
text
box is automatically populated. However, the Stock Code does not store
the
value in the table and only displays on the Form. It is because the
Control
Source for Stock Code is:

=[cboProducts].[Column](1)


And for the Product Combo Box the code is:

Private Sub Product_AfterUpdate()
Me.txtStockCode = Me.cboProducts.Column(1)
End Sub

Is there any way I can get this to store the Stock Code in the table.

--
Thank you for your help

Action query on AfterUpdate Event...?

UPDATE T1
SET Field1=NewValue
WHERE Field1=OldValue

@Alex
 
B

BruceM

Newsgroup etiquette is that you stay with the original thread as long as
people are responding. Both John Vinson (John is nothing less than an
Access expert) and I suggested a similar approach. If you did not
understand the response, explaining that you are new to Access, and
requesting clarification, would be the preferred way to handle it.
By way of general terminology, records are stored in tables. Records are
made of fields. When you open a table, the records are the rows and the
fields are the columns. Each record should have a field that uniquely
identifying the record. In an Employees table that field could be
EmployeeID, or in another table such as, say, Vendors it could be an
automatically-assigned number, or any other field or combination of fields
that is unique to that record.
Forms are the interface between the user and the data that are stored in the
table. That table is the form's Record Source. Forms may also be unbound
(not associated with a record source), but the type of form that is bound to
a record source is known as a bound form.
Controls include all of the things you can put onto a form. Text boxes,
combo boxes, check boxes, and a few other things are controls that can be
bound to (associated with) a field in the form's record source. That field
is the Control Source for that control. By making a table the record source
for a form, all of the table's fields are available as control sources.
Other controls such as labels and lines cannot be bound to a control source.
A combo box has rows that drop down. Those rows are the combo box row
source. This is different from the combo box control source, which is a
field in the table (if the combo box is bound, which it doesn't need to be)
to which the combo box is found.
In general, you store information once in a database, and link to it as
needed. There is some debate about how far to take this (do you store the
State abbreviation in many records in a Contacts table, or do you link to a
record in a State table), but there is little question that Products are
typically stored in a separate table. The question for you is why you want
to select the product from the combo box. It would be best to describe a
little bit in real-world terms just what you are trying to do.

Kirt84 said:
Hi Bruce

I wasn't sure what you meant as I am still new to Access. If you have a
solution to this probolem please could you expalin it in a easier way. It
would be much appreciated......
--
Thank you for your help


BruceM said:
Did you not like the answer to this same question you posted yesterday?

Kirt84 said:
Not sure what you mean by this - Please could you explain this again as
I
am
still new to Access.
--
Thank you for your help


:


Kirt84 ha scritto:

I have a Form and within the Form there is a Subform which contains
a
Combo
Box (Products) which is bound to a table. The Combo Box has two
columns -
Product and Stock Code. Each time a Product is selected the Stock
Code
text
box is automatically populated. However, the Stock Code does not
store
the
value in the table and only displays on the Form. It is because the
Control
Source for Stock Code is:

=[cboProducts].[Column](1)


And for the Product Combo Box the code is:

Private Sub Product_AfterUpdate()
Me.txtStockCode = Me.cboProducts.Column(1)
End Sub

Is there any way I can get this to store the Stock Code in the
table.

--
Thank you for your help

Action query on AfterUpdate Event...?

UPDATE T1
SET Field1=NewValue
WHERE Field1=OldValue

@Alex
 

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

Similar Threads


Top