LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default ADO & SQL

INSERT INTO rewuires a list of the VALUES to be inserted as well.

sSQLString = "INSERT INTO tblBASE_SIDERCA (MILL, ORDER, ITEM, CUSTOMER,
SALE_COND, VESSEL, TYPE_ORDER, ORIGIN_PORT, ID_FINAL_DEST, FINAL_DESTINATION,
ID_EMB, OWNER, TONS, DEPARTURE_DATE, TT_TTS, REQ_DATE)"

sSQLString = SSQLString & " VALUES(" & valuelist & ")"

now valuelist is the data to be loaded/ number are ok but text needs to be
wrapped in single qiotes, eg
'abc',123,'def',3,'more text'

HTH








"Santiago" wrote:

Continuing with the lessons... (sorry I'm new at ADO & SQL and I'm having
many headaches...)

I try to insert records into the tblBASE with SQL, but cannot make it work
either. Here's my code. Thanks guys!!

First I define the "sSQLstring" like this and call the next sub:

Dim sSQLString As String

sSQLString = "INSERT INTO tblBASE_SIDERCA (MILL, ORDER, ITEM, CUSTOMER,
SALE_COND, VESSEL, TYPE_ORDER, ORIGIN_PORT, ID_FINAL_DEST, FINAL_DESTINATION,
ID_EMB, OWNER, TONS, DEPARTURE_DATE, TT_TTS, REQ_DATE)"

Call uploadData(sSQLString)



and here's the uploadData sub...


Public Sub uploadData(sSQL As String)

Dim fila As Long
Dim Command As ADODB.Command
Dim sSQLvalues As String
Dim connectionString As String

fila = 5

connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ActiveWorkbook.path & "\Tracking.mdb;" '& _
"User ID=Admin;" & _
"Password=pass;"

Set Command = New ADODB.Command
Command.ActiveConnection = connectionString

Do While Range("A" & fila) < ""

sSQLvalues = sSQL & " VALUES ('" & Range("A" & fila) & "', '" & _
Range("B" & fila) & "', '" & _
Range("C" & fila) & "', '" & _
Range("D" & fila) & "', '" & _
Range("F" & fila) & "', '" & _
Range("G" & fila) & "', '" & _
Range("I" & fila) & "', '" & _
Range("J" & fila) & "', '" & _
Range("K" & fila) & "', '" & _
Range("L" & fila) & "', '" & _
Range("M" & fila) & "', '" & _
Range("O" & fila) & "', '" & _
Range("P" & fila) & "', '#" & _
Format(Range("U" & fila), "mm/dd/yy") & "#', '" & _
Range("AB" & fila) & "', '#" & _
Format(Range("AC" & fila), "mm/dd/yy") & "#')"

MsgBox sSQLvalues

Command.CommandText = sSQLvalues

Call Command.Execute(, , CommandTypeEnum.adCmdText)

fila = fila + 1
Loop

End Sub


THANKS MILLIONS FOR THE HELP!


"Gareth" wrote:

Hah! I bet that's it!

:-)

Dave Patrick wrote:
Try

"SELECT * FROM [tblBASE] WHERE VESSEL LIKE 'MSC%' "


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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



All times are GMT +1. The time now is 10:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"