Hi All,

I want to be able to run queries within Excel like this:

------------------------------------------------------------------------------------------------------

  mysql01 = "select * from some_table"

   ActiveWorkbook.Worksheets.Add
    With ActiveSheet.QueryTables.Add(Connection:= _
        "ODBC;DRIVER={MySQL ODBC 3.51
Driver};SERVER=111.111.11.11;PORT=3306;DATABASE=mydb_name;
USER=my_user_name;PASSWORD=mypassword;OPTION=3; " _
        , Destination:=Range("A1"))
        .CommandText = Array(mysql01)


        .Name = "Query from MyDB"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = True
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .Refresh BackgroundQuery:=False
    End With
--------------------------------------------------------------------------------------------------------------

When I try to run my VBA module, I get a General ODBC error, which
does not help at all.
Can anyone tell me what I am doing wrong here?

Also, I realize there are probably better methods for connecting to
excel, but for now, if anyone can answer this, that would be
fantastic! Thanks!

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to excel-macros@googlegroups.com

<><><><><><><><><><><><><><><><><><><><><><>
Like our page on facebook , Just follow below link
http://www.facebook.com/discussexcel

Reply via email to