I want to be able to run queries ona MySQL database from Excel. It is something I have never done before so I set up a prototype model just to see if I could set up the link. The following code works except that only the ID's are returned, not the 'description'. Oddly, the same query works fine when looking at the same table in a MS SQL database (and MS Access).

Any idea's why? (the UNION seems to be casing the problem as without the UNION all data is returned).

Thanks in advance.


Sub RecordsetwithMYSQL()

'Open Connection and Recordeset
Dim rs As ADODB.Recordset
Dim SQLString As String
Set rs = CreateObject("ADODB.Recordset")

' Define SQL String
SQLString = "SELECT ID, Description from evo_CustomerType WHERE ID <= 10 " & _
"UNION SELECT ID, Description from evo_CustomerType WHERE ID > 30"


'Set Recordset Properties
With rs
.Source = SQLString
.ActiveConnection = "Warehouse-mysql" 'DatabaseName (in ODBC DSN)
.Open
End With

'Return Data to Excel
Sheet1.Range("a1").CopyFromRecordset rs

'Close Recordset
rs.Close
Set rs = Nothing

End Sub