For some reason I am still having problems with this code. I am getting a syntax error in the INSERT INTO line. I have changed the names with no results. I may have not been exactly clear on what I was trying to do. I have two tables in this data base with one form. On one table I have two columns labled Item and Cost for the supplies that we use per mission. I had to create a form with unbound text boxes labled patient names, date, mission number, and total. The total is calculated by selecting numerous items from a list box and multiplying them by cost and quantity. The second table I have for this form is called Supplies Total. This has two columns labled mission# and Total. What I want to do is create the one button that will save just those two fields only into the supplies total table. I think that the append query is on the right track but the code I tried wasn't working. I did get it to show an error one time stating that this was not an updateable query. Here is the code I inserted in VBA. The text14 is the name of mission number text box on the form. Thanks again for all the help.
- Private Sub Command32_Click()
-
Dim MySQL As String
-
-
MySQL = "INSERT INTO [Supplies_Total](Mission#) VALUES (" & "'" & Me!Text14 & "'" & ");"
-
-
-
DoCmd.SetWarnings False
-
DoCmd.RunSQL MySQL
-
DoCmd.SetWarnings True
-
-
DoCmd.Close acForm, "tfrmHistory"
Two tables, one form. In the second table you want to add the totals?
Does it not work to use a query that combines the two tables into one record source for your form (making the calculations in the query), then bind the totals text box to the correct field in the second table?
As for the code, try using without the second set of "'" in other words: ...VALUES (" & Me!Text14 & ");"
Also, you'll have to remove the DoCmd.Close line (or change the form name from tfrmHistory, unless your form is also named tfrmHistory :-)
Regards,
Scott