SQL Syntax Help for INSERT INTO

Kemidan2014

Board Regular
Joined
Apr 4, 2022
Messages
229
Office Version
  1. 365
Platform
  1. Windows
SQL:
DoCmd.RunSQL "INSERT INTO YokutenTable [(QIMSNum,MakeAction1)] VALUES ('Me.[QIMS#].Value','Me.[CM1].Value')"

I Receive error 3134 on this string i feel like it might be parenthesis or bracket placement the Microsoft description of syntax for INSERT INTO throws a bunch of brackets and parentheses around feild names which i tried to replicate.

i could not find an easier to understand method to simply take fields i already have in my form linked to my main table to copy the values typed in to another table in my DB. (This will be a "by choice" copy. meaning its not a REQUIREMENT from the user that this information goes into the 2nd table) The best method i saw was trying to employ an unbound check box that used a trasnparent shape to engage a macro but to me thats no different than an onclick command button macro.

I do recognize that if i continue using just this string that it will just copy it over and over if the user rapid fire clicks. I need to get over this hurdle before i add something to check for identicle records and put up a warning/exit sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
For numeric values for your fields maybe
SQL:
"INSERT INTO YokutenTable (QIMSNum, MakeAction1) VALUES (" & Me.[QIMS#] & ',' & Me.CM1 & ")"
If your fields/controls are text values, then they need to be delimited ( ' )
SQL:
"INSERT INTO YokutenTable (QIMSNum, MakeAction1) VALUES ('" & Me.[QIMS#] & "','" & Me.CM1 & "')"
Using spaces or special characters in any object name is generally regarded as bad practice. If you're saying a button is a simpler means of executing the sql I have to agree. Perhaps review CurrentDb.Execute method to avoid the warnings you're going to get if you don't disable them. Problem with that is if you disable and code balks and you don't handle the error(s), warnings remain off until the db is reopened.
 
Upvote 0
Solution
Ahh THATS what i was missing the Quotation marks and apostrophes, Thank you for your help!,
 
Upvote 0
You're welcome and thanks for the recognition.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top