By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,121 Members | 1,706 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,121 IT Pros & Developers. It's quick & easy.

Trouble with INSERT INTO Syntax

P: 68
I created a button, when clicked, supposed to create a new record on a different form which is bound to table ‘TProduct’.

Values from these text boxes are to be inserted in to new record in Tproduct.

[Txt_ID]
[txt_Version]
[txt_Total_Cost] – a calculated field
[txt_RecipeStatement] – a calculated field

In addition to these fields update, Vendor ID and Vendor Location are fixed as 10000 and NYC if new record is created this way.

I am having trouble with INSERT INTO statement (Syntax Error). When debugged, Access highlighted entire INSERT INTO phrase.

Can someone help me to correct the syntax? Thanks in advance.

Below is my code.

Expand|Select|Wrap|Line Numbers
  1.  Dim dbs As Database
  2. Set dbs = CurrentDb
  3.  
  4. Dim strRID As String
  5. Dim strRver As String
  6. Dim strCost As Currency
  7. Dim strStatement As String
  8.  
  9.  
  10. strRID = Me.[Txt_ID]
  11. strRver = Me.[txt_Version]
  12. strCost = Me.[txt_Total_Cost]
  13. strStatement = Me.[txt_RecipeStatement]
  14.  
  15. MsgBox [strRID]
  16. MsgBox [strCost]
  17. MsgBox [strRver]
  18. MsgBox [strStatement]
  19.  
  20. dbs.Execute " INSERT INTO TProduct " _
  21. & "(productID, ProductVersion, unit$, spec, vendorID, VendorLocation) VALUES " _
  22. & "('" & strRID & "' , '" & strRver & "', '" & strCost & "', '" & strStatement & "', '10000', 'NYC');"
  23.  
  24. dbs.Close 
Apr 13 '12 #1

✓ answered by Rabbit

If I had to guess, it's probably the unit$ field. I would rename it if I were you.

Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,366
If I had to guess, it's probably the unit$ field. I would rename it if I were you.
Apr 13 '12 #2

P: 68
Yes, you are right. I removed the unit$ from the INSERT INTO phrase and the code worked just fine. Thanks for the hint.

Now I have to rename the field and update all related links.

Joe
Apr 14 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.