Re: Problem with INSERT INTO (SQL) statement in VBA

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



You might also use

Dim strSQL As String

strSQL = "INSERT INTO tblEmp " & _
"(empName, Group, LOCATION, [Group Name], Title, Start_Date) " & _
"VALUES(""" & Forms!Form_AddUser!fname & ' ' & _
Forms!Form_AddUser!lname & """, """ & _
Forms!Form_AddUser!group & """, " & loc & ", """ & _
Forms!Form_AddUser!GName & """, """ & _
Forms!Form_AddUser!title & """, " & _
Format(Forms!Form_AddUser!DTPicker1, "\#yyyy\-mm\-dd\#") & ")"
Debug.Print strSQL
DoCmd.RunSQL strSQL

Once the code runs (and fails), go to the Immediate Window (Ctrl-G) and post
back what appears there.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Ken Snell (MVP)" <kthsneisllis9@xxxxxxxxxxxxxxxxxx> wrote in message
news:O8ri9ofMIHA.1208@xxxxxxxxxxxxxxxxxxxxxxx
Post the code that you now have; likely there is a typo still.
--

Ken Snell
<MS ACCESS MVP>


"ruchie" <ruchie.sharma@xxxxxxxxx> wrote in message
news:4e06aa61-c94c-4f50-99c2-a10b76487bc5@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Ken/Douglas,

I tried your methods, but it is still giving me the same run-time
error (3134 - syntax error in INSERT INTO statement).
Also, i do want to mention that 'loc' is a numeric field.
please guide me how to make this work!
thanks a lot guys




.



Relevant Pages

  • Using DDL to Create Constraint - Syntax Error
    ... get a syntax error on the third DDL SQL statement. ... Dim strSQL As String ... dbsTemp.Execute strSQL, dbFailOnError ...
    (microsoft.public.access.queries)
  • Re: My Brain Hurts - Help
    ... If you must fill in all the fields that would be returned by the select statement, this would account for me getting an error, but why it appears as "Syntax error in INSERT INTO statement." ... strSQL = "Select * FROM Clients;" da = New OleDb.OleDbDataAdapter(strSQL, Conn) 'Create data adapter ... I have tried changing the strSQL text so that it is more complex and it makes no difference. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: VB INSERT INTO
    ... Numeric value shouldn't have quotes around them, so if, for example, ... -2147217900 Syntax error in INSERT INTO statement. ... strSQL" without the quotes. ... Set conDatabase = CurrentProject.Connection ...
    (microsoft.public.access.modulesdaovba)
  • RE: I cannot see the syntax error - guidance please.
    ... compare to your vba and easily spot problems. ... Error 3134 Syntax error in INSERT INTO ... DBEngine.Execute strsql, dbFailOnError ...
    (microsoft.public.access.modulesdaovba)
  • Re: VB INSERT INTO
    ... Debug.Print strSQL ... When your code executes, go to the Immediate Window and ... Numeric value shouldn't have quotes around them, so if, for example, ... -2147217900 Syntax error in INSERT INTO statement. ...
    (microsoft.public.access.modulesdaovba)