Thread: ADO & SQL
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Santiago[_2_] Santiago[_2_] is offline
external usenet poster
 
Posts: 26
Default ADO & SQL

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%' "