oops, the statement should be as:
SQL = "INSERT INTO tblBoats ( StockNo, [Year], Make, Model ) VALUES (" & strStockNo & ", " & strYear & ", '" & strMake & "', '" & strModel & "')"
Main Topics
Browse All Topics
Can someone help me to modify this append query?
--------------------------
Private Sub cmdPublish_Click()
Dim SQL As String
SQL = "INSERT INTO boats ( StockNo, [Year], Make, Model ) VALUES ('STK', '1999', 'Parker', '2320')"
DoCmd.RunSQL SQL
End Sub
--------------------------
OK- my ODBC connection to MySQL works. Now I want to put real data in.
Let's say I had either a control on a form or a field in a table. For example:
tblBoats
StockNo (text)
Year (int)
Make (text)
Model (text)
Or simply controls on a form containing values, for ex:
txtControlStockNo
txtControlYear
txtControlMake
txtControlModel
Can someone provide me with an example of the correct syntax within VBA to modify my append query?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I'm not sure if you want to go through the trouble of setting everything to variables before adding into your query, if you dont, just use this syntax
Private Sub cmdPublish_Click()
Dim SQL As String
SQL = "INSERT INTO tblBoats ( StockNo, [Year], Make, Model ) VALUES ('" & me!
txtControlStockNo & "', " & me!txtControlYear & ", '" & me!txtControlMake & "', '" & me!txtControlModel & "')"
DoCmd.RunSQL SQL
End Sub
By the way, you should maybe look at changing the field name "Year" to something a little different like intYear or Yr
Year() is a vba fucntion and could cause problems down the road.
Business Accounts
Answer for Membership
by: ryancysPosted on 2004-11-27 at 05:30:49ID: 12685898
try like:
","''") ''") "''")
Private Sub cmdPublish_Click()
Dim SQL As String
strStockNo = replace$("" & txtControlStockNo.value,"'
strYear = txtControlYear.value
strMake = replace$("" & txtControlMake.value,"'","
strModel = replace$("" & txtControlModel.value,"'",
SQL = "INSERT INTO boats ( StockNo, [Year], Make, Model ) VALUES (" & strStockNo & ", " & strYear & ", '" & strMake & "', '" & strModel & "')"
DoCmd.RunSQL SQL
End Sub