problem sql

They have: 5,633 posts

Joined: Jan 1970

I'm having a problem with my sql statement(Insert Into command), when i try to run the project an error occurs "Line1: Incorrect syntax near 's'.

I've checked my sql statement already and I dont find any
incorrect syntax, actually when I run the code it performs smoothly but when I try to insert another record the error occurs.

is it also okay to create a control array on my textboxes can this also be one of the possible causes of the error.

Can you also give me a tip to trap any possible errors that can occur on the future.

Pls. reply to me, I badly need this one..

here's my code:

Private Sub Update()

Dim cnn1 As ADODB.Connection
Dim rstCreditScoring As ADODB.Recordset
Dim ssql As String
Dim strcnn As String

strcnn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Credit_Scoring;Data Source=rrcb_01_rscc"

Set rstCreditScoring = New ADODB.Recordset

ssql = "INSERT INTO tblCreditScore(CreditScore,CreditStatus,LastName,FirstName,MiddleName,MonthlyIncome,Age,HomeOwnership,ResAtHomeAdd,EmploymentStatus,ResAtCurrentJob,PositionType,CarOwnership,CreditCards,ProofBillAdd,IDtype,ProvContactPerson,ProvContactNumber,ContactPerson,ContactNumber,BankAccts)VALUES" _
& "( " & txtscore & " , ' " & txtstatus & " ', ' " & txtlastname(0) & " ',' " & txtfirstname(1) _
& " ' , ' " & txtmiddlename(2) & " ' , ' " & Combo1 & " ', ' " & cboage(3) & " ' , ' " & cboownership(2) & " ', ' " & cbocurrentaddress(1) & " ', ' " & cboemployment(4) & " ' , ' " & cbocurrentjob(5) & " ' , ' " & cboposition(6) & " ' , ' " _
& cbocar(7) & " ', ' " & cbocreditcards(13) & " ', ' " & cbobillingaddress(Cool & " ' , ' " & cboid(11) & " ', ' " & cbocontactperson(10) & " ' , ' " & cbocontactnumber(9) & " ' , ' " & maskcontactperson & " ' , " & maskcontactnumber & " , ' " _
& cbobankaccounts(12) & " ', " & txtdate & ")"

rstCreditScoring.Open ssql, strcnn

MsgBox "ok"

End Sub

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Hi jinxie17, and welcome to TWF!

Try putting a space before VALUES in your query.
Also, print the query to the screen befor you execute it, this will help in the debug.
I think you will want to take the space off the begining and end of your fields.

Private Sub Update()

Dim cnn1 As ADODB.Connection
Dim rstCreditScoring As ADODB.Recordset
Dim ssql As String
Dim strcnn As String


strcnn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Credit_Scoring;Data Source=rrcb_01_rscc"

Set rstCreditScoring = New ADODB.Recordset

ssql = "INSERT INTO tblCreditScore (CreditScore, CreditStatus, LastName, FirstName, MiddleName, MonthlyIncome, Age, HomeOwnership, ResAtHomeAdd, EmploymentStatus, ResAtCurrentJob, PositionType, CarOwnership, CreditCards, ProofBillAdd, IDtype, ProvContactPerson, ProvContactNumber, ContactPerson, ContactNumber, BankAccts) VALUES" _
& "(" & txtscore & ", '" & txtstatus & "', '" & txtlastname(0) & "', '" & txtfirstname(1) _
& "' ,'" & txtmiddlename(2) & "' , '" & Combo1 & "', '" & cboage(3) & "' , '" & cboownership(2) & "', '" & cbocurrentaddress(1) & "', '" & cboemployment(4) & "' , '" & cbocurrentjob(5) & "' , '" & cboposition(6) & "' , '" _
& cbocar(7) & "', '" & cbocreditcards(13) & "', '" & cbobillingaddress(8) & "' , '" & cboid(11) & "', '" & cbocontactperson(10) & "' , '" & cbocontactnumber(9) & "' , '" & maskcontactperson & "' , " & maskcontactnumber & " , '" _
& cbobankaccounts(12) & "', " & txtdate & ")"

repsonse.write "<BR>" & vbCrLf & ssql & vbCrLf & "<BR>"

rstCreditScoring.Open ssql, strcnn

MsgBox "ok"

End Sub
'

PS - use [ code ] blah [ /code] tags (without spaces) to show preformated code.

Mark Hensler
If there is no answer on Google, then there is no question.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.