G
Greg
I have a spreadsheet "C:\myWorkbook1.xls" with a named range
"mydatabase"
mydatabase range spans a1:C4 and contains the following data:
Name Age Address
Bill 25 Ohio
Joe 30 New York
Mary 35 New Jersey
The Column headings "Name, Age and Address" are in row 1 (or A1:C1)
I found some code on the Word MVP FAQ website:
http://word.mvps.org/FAQs/InterDev/XLToWordWithDAO.htm
Sub Test()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = OpenDatabase("C:\myBook1.xls", False, False, "Excel 8.0")
Set rs = db.OpenRecordset("SELECT * FROM `mydatabase`")
While Not rs.EOF
MsgBox rs.Fields(0).Value
rs.MoveNext
Wend
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
I would expect the While Not rs.EOF process to return:
Name
Bill
Joe
Mary
as it cycles through the rs first record to last. It actually returns:
Bill
Joe
Mary
It does not return "Name" which is in the within the defined range
"mydatabase," the While Not
rs.EOF seems to skip the first row of the range.
I assume that skipping the first RS in the defined range must have
something to do with how this line is constructed:
Set rs = db.OpenRecordset("SELECT * FROM `mydatabase`")
There is no explanation of that line in the FAQ article and I can find
no explanation in the VBA help file either. Especially related to the
"*."
Can anyone enlighten me as to why the first row in my defined range is
skipped when I run the code above?
Thanks.
"mydatabase"
mydatabase range spans a1:C4 and contains the following data:
Name Age Address
Bill 25 Ohio
Joe 30 New York
Mary 35 New Jersey
The Column headings "Name, Age and Address" are in row 1 (or A1:C1)
I found some code on the Word MVP FAQ website:
http://word.mvps.org/FAQs/InterDev/XLToWordWithDAO.htm
Sub Test()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = OpenDatabase("C:\myBook1.xls", False, False, "Excel 8.0")
Set rs = db.OpenRecordset("SELECT * FROM `mydatabase`")
While Not rs.EOF
MsgBox rs.Fields(0).Value
rs.MoveNext
Wend
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
End Sub
I would expect the While Not rs.EOF process to return:
Name
Bill
Joe
Mary
as it cycles through the rs first record to last. It actually returns:
Bill
Joe
Mary
It does not return "Name" which is in the within the defined range
"mydatabase," the While Not
rs.EOF seems to skip the first row of the range.
I assume that skipping the first RS in the defined range must have
something to do with how this line is constructed:
Set rs = db.OpenRecordset("SELECT * FROM `mydatabase`")
There is no explanation of that line in the FAQ article and I can find
no explanation in the VBA help file either. Especially related to the
"*."
Can anyone enlighten me as to why the first row in my defined range is
skipped when I run the code above?
Thanks.