Thread: ADO & SQL
View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Gareth[_6_] Gareth[_6_] is offline
external usenet poster
 
Posts: 158
Default ADO & SQL

What do you mean by "cannot make this query work"? Cab you be more specific?

Does this SQL string work in Access?

Do you get an error message in Excel or just no records returned? Since
your simpler query works I would suspect it is a problem on the Access
end rather than with VBA.

HTH
G

Santiago wrote:
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