P
PC_User
I'm developing code to download Yahoo stock quotes into MS Access 2K. I have
two public functions in a module. One that creates a temporary table and the
other fills it with data from Yahoo. Actually, it's suppose to do that when
I get it to work. All the Yahoo datafiles are listed on
http://datatables.org/alltables.env and I'm wondering if I can query them
like a table on any other remote server. There are a list of parameters that
the URL must have to select each field; so I've tried to include that in this
sample code. Below my code are a list of websites that I've been using to
develop this code. My question is how can I use the Yahoo data parameters to
insert their data into the temporary table.
**********************************************************************
Option Compare Database
Option Explicit
'Parameters for queries
Dim strSelect As String, strFrom As String
Dim strJoin As String, strWhere As String
Dim strOrderBy As String, strSQL As String
'Parameters for recordset
Dim db As DAO.Database, tblDef As DAO.TableDef
Dim rst1 As DAO.Recordset, rst2 As DAO.Recordset, rst3 As DAO.Recordset
Dim intRecCount1 As Integer, intRecCount2 As Integer
Dim i As Integer, j As Integer
' Flat file coversion
Public Function MakeQuoteTable() ' Make a new temporary table
"tmpYahooDownload"
On Error GoTo Whoops
Dim sTable As String
sTable = "tmpYahooDownload"
DBEngine(0)(0).TableDefs.Delete sTable
Dim db As Database
Dim tblDef As TableDef
Set db = CurrentDb()
Set tblDef = db.CreateTableDef(sTable)
With tblDef
'Ask,AverageDailyVolume,Bid,AskRealtime,BidRealtime,BookValue,
Change&PercentChange,Change,Commission,
.Fields.Append .CreateField("Ask", dbText)
.Fields.Append .CreateField("AverageDailyVolume", dbText)
.Fields.Append .CreateField("Bid", dbText)
.Fields.Append .CreateField("AskRealtime", dbText)
.Fields.Append .CreateField("BidRealtime", dbText)
.Fields.Append .CreateField("BookValue", dbText)
.Fields.Append .CreateField("Change&PercentChange", dbText)
.Fields.Append .CreateField("Change", dbText)
.Fields.Append .CreateField("Commission", dbText)
End With
db.TableDefs.Append tblDef
Call InsertQuoteData
OffRamp:
Exit Function
Whoops:
MsgBox "Error #" & Err & ": " & Err.Description
Resume OffRamp
End Function
' ==================================================================
Public Function InsertQuoteData() ' Insert data into "twmFields"
Dim DataURL As String
Dim db As Database
Dim sTable As String
Dim strSymbol As String, QuoteSource As String
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
sTable = "tmpYahooDownload"
strSymbol = frmCurrentForm.Symbol
DataURL = "http://download.finance.yahoo.com/d/quotes.csv?" & _
"f=aa2bb2b3b4cc1c3" & _
"&s=" & strSymbol
QuoteSource = "http://ichart.finance.yahoo.com/table.csv?"
'Insert data into temporary table.
Set db = CurrentDb()
Set rst1 = db.OpenRecordset(sTable, dbOpenDynaset) 'Target
Set rst2 = db.OpenRecordset(QuoteSource) 'Source
rst2.MoveFirst
Do Until rst2.EOF
With rst1
.AddNew
'Ask,AverageDailyVolume,Bid,AskRealtime,BidRealtime,BookValue,
Change&PercentChange,Change,Commission,
![Ask] = rst2!a
![AverageDailyVolume] = rst2!a2
![Bid] = rst2!b
![AskRealtime] = rst2!b2
![BidRealtime] = rst2!b3
![BookValue] = rst2!b4
![Change&PercentChange] = rst2!c
![Change] = rst2!c1
![Commission] = rst2!c3
.Update
End With
rst2.MoveNext
Loop
rst1.MoveLast
rst1.MoveFirst
intRecCount1 = rst1.RecordCount
Debug.Print "intRecCount1 = " & intRecCount1
rst2.MoveLast
rst2.MoveFirst
intRecCount2 = rst2.RecordCount
Debug.Print "intRecCount2 = " & intRecCount2
rst2.Close
Set rst2 = Nothing
rst1.Close
Set rst1 = Nothing
db.Close
Set db = Nothing
End Function
**********************************************************************
Thanks,
PC
REFERENCES:
Dirk Eddelbuettel Finance
http://dirk.eddelbuettel.com/code/yahooquote.html
Downloading Yahoo Stock Quotes
http://www.spreadsheetml.com/finance/freed...ockquotes.shtml
Yahoo Data Download
http://www.gummy-stuff.org/Yahoo-data.htm
Yahoo! Query Language
http://developer.yahoo.com/yql/
Example
http://www.yqlblog.net/blog/2009/06/02/get...en-data-tables/
Yahoo! Developer Network
http://developer.yahoo.com/
two public functions in a module. One that creates a temporary table and the
other fills it with data from Yahoo. Actually, it's suppose to do that when
I get it to work. All the Yahoo datafiles are listed on
http://datatables.org/alltables.env and I'm wondering if I can query them
like a table on any other remote server. There are a list of parameters that
the URL must have to select each field; so I've tried to include that in this
sample code. Below my code are a list of websites that I've been using to
develop this code. My question is how can I use the Yahoo data parameters to
insert their data into the temporary table.
**********************************************************************
Option Compare Database
Option Explicit
'Parameters for queries
Dim strSelect As String, strFrom As String
Dim strJoin As String, strWhere As String
Dim strOrderBy As String, strSQL As String
'Parameters for recordset
Dim db As DAO.Database, tblDef As DAO.TableDef
Dim rst1 As DAO.Recordset, rst2 As DAO.Recordset, rst3 As DAO.Recordset
Dim intRecCount1 As Integer, intRecCount2 As Integer
Dim i As Integer, j As Integer
' Flat file coversion
Public Function MakeQuoteTable() ' Make a new temporary table
"tmpYahooDownload"
On Error GoTo Whoops
Dim sTable As String
sTable = "tmpYahooDownload"
DBEngine(0)(0).TableDefs.Delete sTable
Dim db As Database
Dim tblDef As TableDef
Set db = CurrentDb()
Set tblDef = db.CreateTableDef(sTable)
With tblDef
'Ask,AverageDailyVolume,Bid,AskRealtime,BidRealtime,BookValue,
Change&PercentChange,Change,Commission,
.Fields.Append .CreateField("Ask", dbText)
.Fields.Append .CreateField("AverageDailyVolume", dbText)
.Fields.Append .CreateField("Bid", dbText)
.Fields.Append .CreateField("AskRealtime", dbText)
.Fields.Append .CreateField("BidRealtime", dbText)
.Fields.Append .CreateField("BookValue", dbText)
.Fields.Append .CreateField("Change&PercentChange", dbText)
.Fields.Append .CreateField("Change", dbText)
.Fields.Append .CreateField("Commission", dbText)
End With
db.TableDefs.Append tblDef
Call InsertQuoteData
OffRamp:
Exit Function
Whoops:
MsgBox "Error #" & Err & ": " & Err.Description
Resume OffRamp
End Function
' ==================================================================
Public Function InsertQuoteData() ' Insert data into "twmFields"
Dim DataURL As String
Dim db As Database
Dim sTable As String
Dim strSymbol As String, QuoteSource As String
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm
sTable = "tmpYahooDownload"
strSymbol = frmCurrentForm.Symbol
DataURL = "http://download.finance.yahoo.com/d/quotes.csv?" & _
"f=aa2bb2b3b4cc1c3" & _
"&s=" & strSymbol
QuoteSource = "http://ichart.finance.yahoo.com/table.csv?"
'Insert data into temporary table.
Set db = CurrentDb()
Set rst1 = db.OpenRecordset(sTable, dbOpenDynaset) 'Target
Set rst2 = db.OpenRecordset(QuoteSource) 'Source
rst2.MoveFirst
Do Until rst2.EOF
With rst1
.AddNew
'Ask,AverageDailyVolume,Bid,AskRealtime,BidRealtime,BookValue,
Change&PercentChange,Change,Commission,
![Ask] = rst2!a
![AverageDailyVolume] = rst2!a2
![Bid] = rst2!b
![AskRealtime] = rst2!b2
![BidRealtime] = rst2!b3
![BookValue] = rst2!b4
![Change&PercentChange] = rst2!c
![Change] = rst2!c1
![Commission] = rst2!c3
.Update
End With
rst2.MoveNext
Loop
rst1.MoveLast
rst1.MoveFirst
intRecCount1 = rst1.RecordCount
Debug.Print "intRecCount1 = " & intRecCount1
rst2.MoveLast
rst2.MoveFirst
intRecCount2 = rst2.RecordCount
Debug.Print "intRecCount2 = " & intRecCount2
rst2.Close
Set rst2 = Nothing
rst1.Close
Set rst1 = Nothing
db.Close
Set db = Nothing
End Function
**********************************************************************
Thanks,
PC
REFERENCES:
Dirk Eddelbuettel Finance
http://dirk.eddelbuettel.com/code/yahooquote.html
Downloading Yahoo Stock Quotes
http://www.spreadsheetml.com/finance/freed...ockquotes.shtml
Yahoo Data Download
http://www.gummy-stuff.org/Yahoo-data.htm
Yahoo! Query Language
http://developer.yahoo.com/yql/
Example
http://www.yqlblog.net/blog/2009/06/02/get...en-data-tables/
Yahoo! Developer Network
http://developer.yahoo.com/