I have this VBA below that is designed to loop through each WS and insert the top 4 rows of each data set.
This works fine inside of a with, but that only lets me specify one sheet, instead of going through them all. I took the with out and got “Invalid or unqualified reference”. After this I added ActiveSheet. to the ‘Cells’ Method.
Now I’m getting this error below:
“ODBC driver doesn’t support the requested properties”
How do I qualify .Cells now? Or is there an alternative? I’m using excel 2010 and mysql.
Public Function InsertData()
Dim rs As ADODB.Recordset
Dim oConn As ADODB.Connection
Dim WS As Worksheet
Dim strsql As String
Set rs = New ADODB.Recordset
Set oConn = New ADODB.Connection
oConn.Open "DRIVER={MySQL ODBC 5.1 Driver};" & _
"SERVER=server.host.com;" & _
"DATABASE=datatime;" & _
"USER=boulders;" & _
"PASSWORD=rocks;" & _
"Option=3"
For Each WS In ActiveWorkbook.Worksheets
For rowcursor = 4 To 8
strsql = "INSERT INTO workflow_metrics (id, code) " & _
"VALUES (" & (ActiveSheet.Cells(rowcursor, 1)) & "," & _
"'" & (ActiveSheet.Cells(rowcursor, 2)) & "')"
rs.Open strsql, oConn, adOpenDynamic, adLockOptimistic
Next
Next WS
End Function
I think you want:
etc.