Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / September 2005

Tip: Looking for answers? Try searching our database.

Runtime Error 3134, Insert Into statement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kevink0217 - 29 Sep 2005 18:36 GMT
Novice with Access, have a question about an Insert Into error.  The
following SQL statement is giving me a headache.

SQL = "INSERT INTO COMPANIES ( Shift, Operator, Date, DTCode, Line,
Hours ) " & _
"SELECT '" & NewShift & "', '" & NewOp & "', " & NewDate & ", " & NewDT
& ", '" _
& NewLine & "', " & NewHr & ""

I am trying to insert some manufacturing data into a database.  Any
Ideas?
Tim Ferguson - 30 Sep 2005 17:36 GMT
> SQL = "INSERT INTO COMPANIES ( Shift, Operator, Date, DTCode, Line,
> Hours ) " & _
> "SELECT '" & NewShift & "', '" & NewOp & "', " & NewDate & ", " & NewDT
> & ", '" _
> & NewLine & "', " & NewHr & ""

This looks like a total mess: using the SELECT syntax really needs a FROM
clause. If you want to pass literal values, then use the VALUES syntax.

If you want to pass literal values, you simply have to handle correct
formatting and delimiters yourself explicitly. You may have unbalanced
quote marks.

Date is a reserved word in just about very language you'll come across
and is a rubbish name for a column. Same probably applies to Line and
Hours although they actually might be legal. Enclose them in [brackets]
just to be sure.

Try this:

 SQL = "INSERT INTO Companies " & vbNewLine & _
   "(Shift, [Operator], [Date], " & _
   "DTCode, [Line], [Hours]) " & vbnewline & _
   "VALUES ( " & SQLString(NewShift) & ", " & vbnewline & _
   "    " & SQLString(NewOp) & ", " & vbnewline & _
   "    " & SQLDate(NewDate) & ", " & vbnewline & _
   "    " & Format(NewDt,"0.00") & ", " & vbnewline & _
   "    " & SQLString(NewLine) & ", " & vbnewline & _
   "    " & Format(NewHr, "0000000") & vbnewline & ")"

 Debug.Assert vbYes=MsgBox(SQL, vbYesNo, "Is this OK?"


The conversion functions look like
 
 public function SQLString(SomeString as String) as string

   somestring = """" & _
     Replace(SomeString, """", """""") & _
     """"

 end function

 public function SQLDate(SomeDate as variant) as string
    ' Jet is not regionally aware: use international
    ' or USA date formats only!!
   const jetDateFormat = "\#yyyy\-mm\-dd\#"

   if isnull(SomeDate) Then
     SQLDate = "NULL"
   else
     SQLDate = Format(SomeDate, jetDateFormat)
   End if

 end function

Formatting numbers is probably trivial, but that is up to you of course.

Hope that helps

Tim F
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.