JumboCactuar
Well-known Member
- Joined
- Nov 16, 2016
- Messages
- 788
- Office Version
- 365
- Platform
- Windows
Hi,
i currently use the following and add a reference to:
Works fine with SQL server, but if i use MYSQL it does sometimes crash and fails to connect.
Is there any better method ?
i currently use the following and add a reference to:
Works fine with SQL server, but if i use MYSQL it does sometimes crash and fails to connect.
Is there any better method ?
VBA Code:
Public Function MyConnection()
MyConnection = "Driver={SQL Server};Server=xxx;Database=xxx;Uid=xxx;Pwd=xxx;"
End Function
VBA Code:
Sub GetData()
Set cnn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cnn.Open (MyConnection)
SQLquery = "SELECT * FROM TABLE1"
rs.Open SQLquery, cnn
Sheet1.Cells.ClearContents
Sheet1.Range("A2").CopyFromRecordset rs
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub