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

Just to add some (maybe) useful info: if the sSQLstring is:

sSQLString = "SELECT * FROM [tblBASE]"

the query brings every record in the table, but cannot filter MSC* in the
sql query...

thanks.

bregards
Santiago

"Santiago" wrote:

I cannot make this query work...

first I make the sql string like this:

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

Then I use this string in the following code, connecting to an Access
database. I just want to retreive data of all records where vessel starts
with "MSC".

Public Sub retrieveData(sSQL As String)

Dim RECSET As ADODB.Recordset
Dim connectionString As String
Dim fila As Long
Dim sheet As Worksheet

Set sheet = ActiveSheet


connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ActiveWorkbook.path & "\Tracking.mdb;"

fila = 5

Set RECSET = New ADODB.Recordset
Call RECSET.Open(sSQL, _
connectionString, , , _
CommandTypeEnum.adCmdText)

If Not RECSET.EOF Then

Call sheet.Range("a" & fila).CopyFromRecordset(RECSET)

Else

Call MsgBox("Error: No data found", vbCritical)

End If

With sheet.Range("5:5000")
.RowHeight = 15
End With

If (RECSET.State And ObjectStateEnum.adStateOpen) Then RECSET.Close
Set RECSET = Nothing

End Sub

Any idea that may help me???

thanks! bregards Santiago