'*' in sql instruction

G

gatarossi

Dear all,

I have a dificulty problem:

I have created a simple access database with this fields: autonum,
entity, product, sales_amt.

I'm trying to do a VBA code in excel to bring the data from access,
using the * to bring all data, but it doesn't work.

I don't know why it doesn't work, but I know if I pick the sql code
and put it in an access consult, it works!!!

I put directly the * in the code, but in my real code, a have some
variables that in some cases will result in *, in both cases, it
doesn't work...

I'm doing something wrong???

Thanks in advance!!!!

Public Sub getCn(ByRef dbcon As ADODB.Connection, ByRef dbrs As
ADODB.Recordset, _
sqlstr As String, dbfile As String, usernm As String, pword As String)

Set dbcon = New ADODB.Connection
dbcon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfile &
";", _
usernm, pword

Set dbrs = New ADODB.Recordset
dbrs.Open sqlstr, dbcon

End Sub

Sub test()

Dim adoconn As ADODB.Connection
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String
Dim xlsht As Excel.Worksheet

filenm = ThisWorkbook.Path & "\db_teste.mdb"

Set xlsht = Sheets("Sheet1")

xlsht.Select

Range(Cells(2, 1), Cells(65536, 256)).ClearContents

sql = "SELECT sales_amt.entity, sales_amt.product,
Sum(sales_amt.sales_amt) AS Expr1 FROM sales_amt "
sql = sql & "GROUP BY sales_amt.entity, sales_amt.product "
sql = sql & "HAVING (((sales_amt.entity) Like '*') AND
((sales_amt.product) Like '*')) ;"

Call getCn(adoconn, adors, sql, filenm, "", "")
xlsht.Cells(2, 1).CopyFromRecordset adors

adors.Close
adoconn.Close

Set adors = Nothing
Set adoconn = Nothing
Set xlsht = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Bring Data From Access in a Form 0
Unique Values 2
SQL instruction 1
Bring the heading data in a sql query 0
ADO - password 3
Bring Data from Access 3
Database in Excel 0
SQL - Sum Values 0

Top