it is giving me an run time error 3134 syntax error in insert into statement while clicking on the control.
Private Sub CmdAddNew_Click()
'add data to table
CurrentDb.Execute "INSERT INTO tblemployee(,firstname,lastname,Address,city)" & _
"VALUES('" & Me.txtfirstname & "','" & Me.txtlastname & "','" & Me.txtaddress & "','" & Me.txtcity & "')"
tblemployee(,firstname
Extra comma here?
Related
comm = "INSERT INTO CUST_DETAILS (cust_ID,cust_name,Address,Email-id,Phone_no)"
+ "values ('" & txtID.Text & "','" & txtName.Text & "','"
& txtAdd.Text & "','" & txtEmail.Text & "','" & txtPhone.Text & "')"
What is the error?
VB6 does not automatically know that a line continues after a line break. If you do not use the line continuation character VB6 sees the end of the line as the end of the statement, and the next line as a new statement. So the second and third lines are syntactically incorrect. To fix it add a single space followed by an underscore after the first and second lines to tell the VB6 that the line continues on the next line.
comm = "INSERT INTO CUST_DETAILS (cust_ID,cust_name,Address,Email-id,Phone_no)" _
& "values ('" & txtID.Text & "','" & txtName.Text & "','" _
& txtAdd.Text & "','" & txtEmail.Text & "','" & txtPhone.Text & "')"
MSDN reference here
Also please note I replaced your "+" which will concatenate a string, but is bad practice with an ampersand.
I was trying to run this following SQL through vba, however, it keeps telling there is a syntax error in INSERT INTO statement. Can anyone help with it? Thanks a lot.
Dim strTemp2 As String
strTemp2 = "INSERT INTO tblPartDocs(idsPartDocID, idsScanID, intPartNum, strShopOrder/LotBatchID, dtmDateOfWork) VALUES " _
& "('" & Me.tboScanID & "','" & Me.tboScanID & "','" & Me.tboPartNumber & "','" & Me.tboShop & "','" & Me.tboDateOfWork & "');"
DoCmd.RunSQL strTemp2
I think problem is here
"strShopOrder/LotBatchI"
You are require to provide comma instead of forward slash
Complete VBA newb...trying to enter some simple data into a simple table from an access form.
I used a youtube video and attempted to modify the code for my use, however I can get seem to get passed errors.
Here is the code mapped to the button that I am using to enter in the data
Private Sub Command0_Click()
'add data to table
CurrentDb.Execute "INSERT INTO EmpLunchTBL (FullName, ManName, TuesOrder, ThursOrder, PayType)" & _
"VALUES (" ' & Me.txtName & ",'" & Me.txtMS & "','" & Me.cboTues & "','" & Me.cboThurs & "','" & Me.cboPaytype & "')"
End Sub
Pretty Straight forward, I know the issue lies somewhere within my values area...but again total newb...
Thank you!
I think the "VALUES (" ' is the problem. Try this:
Private Sub Command0_Click()
'add data to table
Debug.Print "INSERT INTO EmpLunchTBL (FullName, ManName, TuesOrder, ThursOrder, PayType)" & _
"VALUES ('" & Me.txtName & "','" & Me.txtMS & "','" & Me.cboTues & "','" & Me.cboThurs & "','" & Me.cboPaytype & "')"
End Sub
Edit: Another single quote was missing.
I have this code I have been working on to add data to a table. And there is a portion of code that is being highlighted with the error message RUN TIME ERROR 3061: TOO FEW PARAMETERS. EXPECTED 1
And I cannot figure out what the issue is and what I am missing. The following is the portion of code being highlighted.
CurrentDb.Execute "INSERT INTO KWTable(KW, Source, Code) " & _
" VALUES(" & Me.text_key & ",'" & Me.txt_code & "','" & _
Me.combo_source & "')"
Try
dim ssql as string
ssql = "INSERT INTO KWTable(KW, Source, Code) " & _
" VALUES(" & Me.text_key & ",'" & Me.txt_code & "','" & _
Me.combo_source & "')"
debug.print ssql
CurrentDb.Execute ssql
For starters, I have practically no knowledge of VBA Code. What I'm trying to do here is take information from a form and subform and enter it as a new record into a table that is set as the record source of the subform.
The error code reads: run time error '3075':
Syntax Error (Missing Operator) in query expression 'GENERAL METAL (CUBEX)'.
Also I apologize for how messy it is. I honestly just tried to copy what I saw in a YouTube video that kind of represented what I was trying to do.
CurrentDb.Execute "INSERT INTO workingorders(customer, partname, partnumber, metal, grade, unitweight, Process, subcontract, MoldDescription, moldlocation, specialconcerns, shippinginst, datereq, orderdate, qtyordered, qtycast) " & _
" VALUES(" & Me.customer & ", '" & Me.partname & "','" & Me.partnumber & "','" & Me.metal & "','" & Me.grade & "','" & Me.unitweight & "','" & Me.Process & "','" & Me.subcontract & "','" & Me.MoldDescription & "','" & Me.moldlocation & _
Me.specialconcerns & "','" & Me.shippinginst & "','" & Me.datereq & "','" & Me.orderdate & "','" & Me.qtyordered & "','" & Me.qtycast & "')"
This part concerns me:
'" & Me.moldlocation & _ Me.specialconcerns & "'
It looks like you're missing the closing quote before the line suppression. Any time you see "& _" it's telling the code that you're moving to a new line, but to supress that line break when the code is run. You generally need to close up your quotes before you do that, just like was done in the other line suppressor:
qtycast) " & _ " VALUES(
So, in short, give this a shot:
CurrentDb.Execute "INSERT INTO workingorders(customer, partname, partnumber, metal, grade, unitweight, Process, subcontract, MoldDescription, moldlocation, specialconcerns, shippinginst, datereq, orderdate, qtyordered, qtycast) " & _
" VALUES(" & Me.customer & ", '" & Me.partname & "','" & Me.partnumber & "','" & Me.metal & "','" & Me.grade & "','" & Me.unitweight & "','" & Me.Process & "','" & Me.subcontract & "','" & Me.MoldDescription & "','" & Me.moldlocation "'," & _
"'" & Me.specialconcerns & "','" & Me.shippinginst & "','" & Me.datereq & "','" & Me.orderdate & "','" & Me.qtyordered & "','" & Me.qtycast & "')"
Since I don't know your data, I'll just remind you that anything that's TEXT needs to be enclosed with single quotes (i.e. '" & Me.grade & "',) and anything that's an INT does not need the single quote (i.e. " & Me.customer & ",). Just make sure all your variables are enclosed accordingly or that will cause an error as well.
If this answers your question, please don't forget to give the answer a checkmark. Thanks!