PavelGur
Programmer
- Sep 21, 2001
- 75
I took the following code from VBA snippets. I modified the names and tried to debug it. I've got compile error on the connection line: Invalid use of keyword new.
Does it mean that Connection keyword does not exist anymore or I need to modify something for Office XP?
Thanks Pavel.
Here is the code:
Sub Accessconn()
Dim conn As New Connection
Dim rec As New Recordset
Dim ws As Worksheet
Dim sql$, i&
Set ws = ThisWorkbook.Worksheets("Price")
conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
"Data Source=NST;"
'"Data Source=" + ThisWorkbook.Path + "\nwind.mdb;"
sql = "SELECT Stock " & _
"FROM STGEN WHERE Direction = -1 ORDER BY Stock"
rec.Open sql, conn
While Not rec.EOF
i = i + 1
ws.[a1].Cells(i) = rec!Stock
rec.MoveNext
Wend
rec.Close: conn.Close
End Sub
Does it mean that Connection keyword does not exist anymore or I need to modify something for Office XP?
Thanks Pavel.
Here is the code:
Sub Accessconn()
Dim conn As New Connection
Dim rec As New Recordset
Dim ws As Worksheet
Dim sql$, i&
Set ws = ThisWorkbook.Worksheets("Price")
conn.Open "Provider=microsoft.jet.oledb.4.0;" + _
"Data Source=NST;"
'"Data Source=" + ThisWorkbook.Path + "\nwind.mdb;"
sql = "SELECT Stock " & _
"FROM STGEN WHERE Direction = -1 ORDER BY Stock"
rec.Open sql, conn
While Not rec.EOF
i = i + 1
ws.[a1].Cells(i) = rec!Stock
rec.MoveNext
Wend
rec.Close: conn.Close
End Sub