2 Replies - 3197 Views - Last Post: 17 November 2012 - 11:49 AM Rate Topic: -----

#1 srisubha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-November 12

syntax error in add new option

Posted 09 November 2012 - 10:37 PM

Private Sub MNUPROSAVE_Click()
str = "insert into profile(rollno,fathername,foccupation,mothername,moccupation,contactno,residentialno,mcontactno,annualincome,permanentaddress,tempaddress,pincode,pemailid,religion,caste,state,city,noofbrothers,noofsisters,schoolorclgstudied)values(' " & rno.Text & " ',' " & fname.Text & " ','" & focc.Text & " ',' " & mname.Text & " ',' " & mocc.Text & " '," & cno.Text & "," & resno.Text & "," & mcno.Text & ", " & ain.Text & " ,' " & pa.Text & " ',' " & ta.Text & " '," & pin.Text & ",' " & pemail.Text & " ',' " & reli.Text & " ',' " & cas.Text & " ',' " & stat.Text & " ',' " & cit.Text & " ', " & nob.Text & " , " & nos.Text & ",' " & sch.Text & "')"
cn.Execute (str)
MsgBox ("DETAILS ADDED ")
End Sub


while executing the above code i got an
run time error'-2147217900(80040e14)'
syntax error in insert into statement

Is This A Good Question/Topic? 0
  • +

Replies To: syntax error in add new option

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5631
  • View blog
  • Posts: 12,078
  • Joined: 02-June 10

Re: syntax error in add new option

Posted 10 November 2012 - 05:25 PM

So break it down until you find something that doesn't look right


Private Sub MNUPROSAVE_Click()
str = 

"insert into profile(rollno,fathername,foccupation,mothername,moccupation,contactno,residentialno,mcontactno,annualincome,permanentaddress,tempaddress,pincode,pemailid,religion,caste,state,city,noofbrothers,noofsisters,schoolorclgstudied)values(' "
 & rno.Text & 
" ',' "
 & fname.Text & 
" ','"
 & focc.Text & 
" ',' "
 & mname.Text & 
" ',' "
 & mocc.Text & 
" ',"           <- where's the other apostrophe?


 & cno.Text & 
","
 & resno.Text & 
"," 
& mcno.Text & 
", " 
& ain.Text & 
" ,' "        <-- Oh, there it is

 & pa.Text & 
" ',' "
 & ta.Text & 
" '," &          <-- opening apostophe
pin.Text & 
",' "            <--- closing apostrophe
 & pemail.Text & 
" ',' "
 & reli.Text & 
" ',' "
 & cas.Text & 
" ',' " 
& stat.Text & 
" ',' " 
& cit.Text & 
" ', "
 & nob.Text & 
" , " & nos.Text & 
",' " & sch.Text & 
"')"
cn.Execute (str)
MsgBox ("DETAILS ADDED ")
End Sub


This isn't my normal thing but... Damn this looks like a mess. Ever think of parameterizing your stuff?

Also, it looked like you had a steady pattern in apostrophy useage - but then it goes wonky. My first guess would be that your final query has the ' and , mixed or mismatched once it is all assembled.

http://www.dreaminco...ery-a-database/
Was This Post Helpful? 2
  • +
  • -

#3 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: syntax error in add new option

Posted 17 November 2012 - 11:49 AM

I can't see any mismatched quotes. it looks, however, like you don't have spaces on both sides of the word "values". That would be a syntax error. If you do, I would check your field names and make sure that you didn't type one in wrong.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1