PC Review


Reply
Thread Tools Rate Thread

INSERT INTO not inserting anything into anything :-( !

 
 
plh
Guest
Posts: n/a
 
      20th Apr 2011
Hi All,
Office 2010:
The whole context is way below, but the gist is that the command:

sSQL = "INSERT INTO tblToolsFiltered " _
&
"(IDOld,Tool,Material,Coating,Type,TNumber,Location1033,Bin,LocationTC,Size)
VALUES " _
& "(" & l & "," & sTool & "," & lMaterial & "," &
lCoating & "," _
& lType & "," & sTNumber & "," & sLocation1033 & "," &
sBin & "," _
& sLocationTC & "," & snSize & ")"
Debug.Print sSQL
d.Execute sSQL

Doesn't put anything into table tblToolsFiltered. When I open it up it
is still empty. There are no errors raised. I would certainly
appreciate some help because I am stumped.

An example of sSQL is:

INSERT INTO tblToolsFiltered
(IDOld,Tool,Material,Coating,Type,TNumber,Location1033,Bin,LocationTC,Size)
VALUES (19,'REAM CARB .0930',1,1,5,'T-12533','','','',0.093)

Thank You!
-plh

Context:

Private Sub cmdFind_Click()
Dim r1 As Recordset
Dim R2 As Recordset
Dim d As Database
Dim l As Long
Dim sSQL, sTool, sTNumber, sLocation1033, sBin, sLocationTC As String
Dim lMaterial, lCoating, lType As Long
Dim snSize As Single
On Error GoTo Hell
Set d = CurrentDb
Set r1 = d.OpenRecordset("tblToolsFiltered")

With r1
Do While .EOF = False
'.Edit
.Delete
'.Update
.MoveNext
Loop
End With
Set R2 = d.OpenRecordset("tblTools", , dbReadOnly)
With R2
Do While .EOF = False
l = .Fields("IDTool")
sTool = "'" & .Fields("Tool") & "'"
sTNumber = "'" & .Fields("TNumber") & "'"
sLocation1033 = "'" & .Fields("Location1033") & "'"
sBin = "'" & .Fields("Bin") & "'"
sLocationTC = "'" & .Fields("LocationTC") & "'"
lMaterial = .Fields("Material")
lCoating = .Fields("Coating")
lType = .Fields("Type")
snSize = .Fields("Size")
If InStr(UCase(.Fields("Tool")), UCase(Me.txtSelect)) > 0
Then
sSQL = "INSERT INTO tblToolsFiltered " _
&
"(IDOld,Tool,Material,Coating,Type,TNumber,Location1033,Bin,LocationTC,Size)
VALUES " _
& "(" & l & "," & sTool & "," & lMaterial & "," &
lCoating & "," _
& lType & "," & sTNumber & "," & sLocation1033 & "," &
sBin & "," _
& sLocationTC & "," & snSize & ")"
Debug.Print sSQL
d.Execute sSQL
End If
.MoveNext
Loop
d.Close
End With
Exit Sub
Hell:
If Err.Number = 3167 Or Err.Number = 94 Then
Resume Next
Else
MsgBox "Error #: " & Err.Number & vbCrLf & "Desc: " &
Err.Description
End If


End Sub
 
Reply With Quote
 
 
 
 
Ken Snell
Guest
Posts: n/a
 
      22nd Apr 2011
You're not including the delimiting ' characters for the string values.

This snippet:
"," & sTool & ","
should be this:
",'" & sTool & "',"

And so on for all the other variables that contain string values.

--

Ken Snell
http://www.accessmvp.com/KDSnell/


"plh" <(E-Mail Removed)> wrote in message
news:d2c50927-faf4-4b43-ab8a-(E-Mail Removed)...
> Hi All,
> Office 2010:
> The whole context is way below, but the gist is that the command:
>
> sSQL = "INSERT INTO tblToolsFiltered " _
> &
> "(IDOld,Tool,Material,Coating,Type,TNumber,Location1033,Bin,LocationTC,Size)
> VALUES " _
> & "(" & l & "," & sTool & "," & lMaterial & "," &
> lCoating & "," _
> & lType & "," & sTNumber & "," & sLocation1033 & "," &
> sBin & "," _
> & sLocationTC & "," & snSize & ")"
> Debug.Print sSQL
> d.Execute sSQL
>
> Doesn't put anything into table tblToolsFiltered. When I open it up it
> is still empty. There are no errors raised. I would certainly
> appreciate some help because I am stumped.
>
> An example of sSQL is:
>
> INSERT INTO tblToolsFiltered
> (IDOld,Tool,Material,Coating,Type,TNumber,Location1033,Bin,LocationTC,Size)
> VALUES (19,'REAM CARB .0930',1,1,5,'T-12533','','','',0.093)
>
> Thank You!
> -plh
>
> Context:
>
> Private Sub cmdFind_Click()
> Dim r1 As Recordset
> Dim R2 As Recordset
> Dim d As Database
> Dim l As Long
> Dim sSQL, sTool, sTNumber, sLocation1033, sBin, sLocationTC As String
> Dim lMaterial, lCoating, lType As Long
> Dim snSize As Single
> On Error GoTo Hell
> Set d = CurrentDb
> Set r1 = d.OpenRecordset("tblToolsFiltered")
>
> With r1
> Do While .EOF = False
> '.Edit
> .Delete
> '.Update
> .MoveNext
> Loop
> End With
> Set R2 = d.OpenRecordset("tblTools", , dbReadOnly)
> With R2
> Do While .EOF = False
> l = .Fields("IDTool")
> sTool = "'" & .Fields("Tool") & "'"
> sTNumber = "'" & .Fields("TNumber") & "'"
> sLocation1033 = "'" & .Fields("Location1033") & "'"
> sBin = "'" & .Fields("Bin") & "'"
> sLocationTC = "'" & .Fields("LocationTC") & "'"
> lMaterial = .Fields("Material")
> lCoating = .Fields("Coating")
> lType = .Fields("Type")
> snSize = .Fields("Size")
> If InStr(UCase(.Fields("Tool")), UCase(Me.txtSelect)) > 0
> Then
> sSQL = "INSERT INTO tblToolsFiltered " _
> &
> "(IDOld,Tool,Material,Coating,Type,TNumber,Location1033,Bin,LocationTC,Size)
> VALUES " _
> & "(" & l & "," & sTool & "," & lMaterial & "," &
> lCoating & "," _
> & lType & "," & sTNumber & "," & sLocation1033 & "," &
> sBin & "," _
> & sLocationTC & "," & snSize & ")"
> Debug.Print sSQL
> d.Execute sSQL
> End If
> .MoveNext
> Loop
> d.Close
> End With
> Exit Sub
> Hell:
> If Err.Number = 3167 Or Err.Number = 94 Then
> Resume Next
> Else
> MsgBox "Error #: " & Err.Number & vbCrLf & "Desc: " &
> Err.Description
> End If
>
>
> End Sub



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
when typing words or anything it is not inserting it is replacing I hate word!!! Microsoft Word Document Management 2 16th Jan 2008 06:47 PM
Very simple INSERT INTO with a DateTime parameter -> "Syntax Error in INSERT INTO statement" loquak Microsoft ADO .NET 3 30th Nov 2004 08:41 PM
Insert | File > Attachmnet-Button Drop Down ;What is the difference between Insert and Insert As Attachmnet Oda Yujiro Microsoft Outlook 4 17th Jun 2004 01:53 AM
Re: Inserting Outlook items (e.g. messages) into a new message used to be easy. Do I really have to save a message to my hard drive first to insert it into a new email in Outlook 2002? Jocelyn Fiorello [MVP - Outlook] Microsoft Outlook Discussion 0 9th Mar 2004 07:05 AM
Can't download anything at ALL from anything... Jason Portell Windows XP Internet Explorer 0 29th Sep 2003 12:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:19 AM.