My Access DB handles product formulation and specification. In the formula form, many text boxes, such as Cost or ingredient statement, are calculated fields based on each ingredient data in the formula.
Once a formula is complete, it becomes an ingredient. The new ingredient ID and Version in the ingredient table (table name TProduct) is supposed to inherit the formula ID and Version. I built a command button to copy ID, Version, cost, and other information from Formula form to Ingredient form using INSERT INTO statement.
However, I am stuck with one issue. If the record already exists, INSERT INTO statement does not update new information in the existing record. User will not notice that the record in Ingredient Table is not updated.
I don’t know how to modify the code to (1) warn user that same ID and Version exists in Ingredient table; (2) delete the existing ingredient record; (3) create a new record with updated information from formula table.
Below is my current INSERT INTO code. Is there a simple way to handle this? Thanks.
Once a formula is complete, it becomes an ingredient. The new ingredient ID and Version in the ingredient table (table name TProduct) is supposed to inherit the formula ID and Version. I built a command button to copy ID, Version, cost, and other information from Formula form to Ingredient form using INSERT INTO statement.
However, I am stuck with one issue. If the record already exists, INSERT INTO statement does not update new information in the existing record. User will not notice that the record in Ingredient Table is not updated.
I don’t know how to modify the code to (1) warn user that same ID and Version exists in Ingredient table; (2) delete the existing ingredient record; (3) create a new record with updated information from formula table.
Below is my current INSERT INTO code. Is there a simple way to handle this? Thanks.
Code:
Dim dbs As Database
Set dbs = CurrentDb
Dim strRID As String
Dim strRver As String
Dim strCost As Currency
Dim strStatement As String
strRID = Me.[Txt_ID]
strRver = Me.[txt_Version]
strCost = Me.[txt_Total_Cost]
strStatement = Me.[txt_RecipeStatement]
dbs.Execute " INSERT INTO TProduct " _
& "(productID, ProductVersion, UnitCost, spec, vendorID, VendorLocation) VALUES " _
& "('" & strRID & "' , '" & strRver & "', '" & strCost & "', '" & strStatement & "', '10000', 'NYC');"
dbs.Close
Comment