With reference to this question: Avoid new line seperators in mySQL query within VBA code, I wanted to execude a SQL
statement that is written in a textbox
in the Excel-File.
Therefore, I created a textbox
called SqlQuery1
looking like this:
In the VBA
I refered to the textbox within the SqlString
:
Sub Get_Data_from_DWH ()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=XX.XXX.XXX.XX; DATABASE=bi; UID=testuser; PWD=test; OPTION=3"
conn.Open
SqlString = ThisWorkbook.Sheet1.Shapes("SqlQuery1").OLEFormat.Object.Text
Set rs = New ADODB.Recordset
rs.Open strSQL, conn, adOpenStatic
Sheet1.Range("A1").CopyFromRecordset rs
rs.Close
conn.Close
End Sub
However, I get runtime error 438
on the SqlString
.
Do you have any idea what I need to change to make it work?