Jaymond Flurrie
Well-known Member
- Joined
- Sep 22, 2008
- Messages
- 919
- Office Version
- 365
- Platform
- Windows
I have established a connection like this
Then I use it like this
this works, but my question is that am I doing the whole download operation here twice? Do I have to do first
and then
or how should I do it?
Code:
Sub InitializeMySQLConn()
Set oConn = New ADODB.Connection
Set rs = New ADODB.Recordset
strConn = ConnString()
End Sub
Function ConnString() As String
ConnString = "DRIVER={MySQL ODBC 5.1 Driver};" & _
"SERVER=myserver;" & _
"DATABASE=mydatabase;" & _
"USER=me;" & _
"PASSWORD=mypassword;" & _
"Option=3"
End Function
Then I use it like this
Code:
oConn.Open strConn
strsql = "SELECT * FROM mytable;"
oConn.Execute strsql
rs.Open strsql, oConn, adOpenDynamic, adLockOptimistic
Set myrange = Range("A1")
myrange.CopyFromRecordset rs
rs.Close
oConn.Close
this works, but my question is that am I doing the whole download operation here twice? Do I have to do first
Code:
oConn.Execute strsql
Code:
rs.Open strsql, oConn, adOpenDynamic, adLockOptimistic