Update the value a field in another table

S

Sammie

I have a command button on a form that creates a new record in another
table. After this is done, I want to update the value of another field
on the new record I just created by copying the value from one field to
another.

My table is called TakeaNumber. It has an autonumber field called
SalesOrderID. I want to copy the value of the [Salesorderid] field
(this is a number field) to the [invoice #] field (this is a text
field). Below is my code to add the new record. Can someone help me
with the additional code to do this?

'Create new Invoice based on this quote.
Dim dbsSuperdatabase As Database
Dim rstTakeaNumber As DAO.Recordset 'table to be updated
'Dim strSQL As String

Set dbsSuperdatabase = CurrentDb
Set rstTakeaNumber = dbsSuperdatabase.OpenRecordset("TakeaNumber")

rstTakeaNumber.AddNew
rstTakeaNumber![Client] = Me![Client]
rstTakeaNumber![Quote#] = Me![Quote#]
rstTakeaNumber![ShipmentID] = Me![ShipmentID]
rstTakeaNumber.Update
rstTakeaNumber.close
Set rstTakeaNumber = Nothing
 
D

Douglas J. Steele

rstTakeANumber![Invoice#] = CStr(rstTakeANumber!Salesorderid)

However, why would you want to store the same value twice in your table?
Instead, take Invoice# out of your table. Create a query that has a computed
field named Invoice# based on the Salesorderid field, and use the query
wherever you would otherwise use the table.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Sammie said:
I have a command button on a form that creates a new record in another
table. After this is done, I want to update the value of another field on
the new record I just created by copying the value from one field to
another.

My table is called TakeaNumber. It has an autonumber field called
SalesOrderID. I want to copy the value of the [Salesorderid] field (this
is a number field) to the [invoice #] field (this is a text field). Below
is my code to add the new record. Can someone help me with the additional
code to do this?

'Create new Invoice based on this quote.
Dim dbsSuperdatabase As Database
Dim rstTakeaNumber As DAO.Recordset 'table to be updated
'Dim strSQL As String

Set dbsSuperdatabase = CurrentDb
Set rstTakeaNumber = dbsSuperdatabase.OpenRecordset("TakeaNumber")

rstTakeaNumber.AddNew
rstTakeaNumber![Client] = Me![Client]
rstTakeaNumber![Quote#] = Me![Quote#]
rstTakeaNumber![ShipmentID] = Me![ShipmentID]
rstTakeaNumber.Update
rstTakeaNumber.close
Set rstTakeaNumber = Nothing
 

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