J
James Garner
Hi,
I am just starting out with trying to program Access via VBA and ADO. I am
having some real difficulties with the connection object and would really
appreciate any advice that anyone could offer.
I have a database of stock quotes with the fields: Ticker, Date, Open, High,
Low, Close & Volume. I am trying to write code which will generate a
recordset of all the price records for a given ticker. The module that I am
writing the function sits in the same project which holds the table itself.
What I have come up with is:-
Dim db As New ADODB.Connection
db.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=" & DataFilename & ";" & _
"DefaultDir=" & DataPath & ";"
SQLcode = "SELECT Ticker,Date,Open,High,Low,Close,Volume " & _
"FROM Prices " & _
"WHERE Ticker = '" & Ticker & "' " & _
"ORDER BY Date"
Dim rs As New ADODB.Recordset
rs.CursorType = adOpenDynamic
Set rs = db.Execute(SQLcode, NumRecs)
All this works fine from Excel, but using the same approach in Access itself
causes problems at the db.Open command. I think it is because the database
is already open (the module itself sits in it). So, what I am wondering is:
how do I get my function to generate this recordset from the database that
it is currently a part of?
Any advice much appreciated!
James.
I am just starting out with trying to program Access via VBA and ADO. I am
having some real difficulties with the connection object and would really
appreciate any advice that anyone could offer.
I have a database of stock quotes with the fields: Ticker, Date, Open, High,
Low, Close & Volume. I am trying to write code which will generate a
recordset of all the price records for a given ticker. The module that I am
writing the function sits in the same project which holds the table itself.
What I have come up with is:-
Dim db As New ADODB.Connection
db.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=" & DataFilename & ";" & _
"DefaultDir=" & DataPath & ";"
SQLcode = "SELECT Ticker,Date,Open,High,Low,Close,Volume " & _
"FROM Prices " & _
"WHERE Ticker = '" & Ticker & "' " & _
"ORDER BY Date"
Dim rs As New ADODB.Recordset
rs.CursorType = adOpenDynamic
Set rs = db.Execute(SQLcode, NumRecs)
All this works fine from Excel, but using the same approach in Access itself
causes problems at the db.Open command. I think it is because the database
is already open (the module itself sits in it). So, what I am wondering is:
how do I get my function to generate this recordset from the database that
it is currently a part of?
Any advice much appreciated!
James.