Thank you very much.

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
PapaDos,
I made the changes that you suggested and confirmed the results.
Thanks again. That solution however presented another problem :-(
Using the same example database:
Name Age Address
Bill 25 Ohio
Joe 30 New York
Mary 35 New Jersey
I want to run a macro to build a table in Word with the data:
Before having your tip, I used:
Sub BuildaTableinWordWithExcelData()
Dim myDB As Database
Dim myActiveRecord As Recordset
Dim i As Long
Dim j As Long
Dim dtable As Table, drow As Row
Set myDB = OpenDatabase("C:\myBook1.xls", False, False, "Excel 8.0")
Set myActiveRecord = myDB.OpenRecordset("mySSRange", dbOpenForwardOnly)
Set dtable = ActiveDocument.Tables.Add(Range:=Selection.Range, _
NumRows:=1, numcolumns:=myActiveRecord.Fields.Count)
Set drow = dtable.Rows(1)
'Add the column header data.
For i = 1 To myActiveRecord.Fields.Count
drow.Cells(i).Range.Text = myActiveRecord.Fields(i - 1).Name
Next i
Set drow = dtable.Rows.Add
'Populate the data
Do While Not myActiveRecord.EOF
For i = 1 To myActiveRecord.Fields.Count
drow.Cells(i).Range.Text = myActiveRecord.Fields(i - 1)
Next i
Set drow = dtable.Rows.Add
myActiveRecord.MoveNext
Loop
drow.Delete
myActiveRecord.Close
myDB.Close
End Sub
Using your suggestion, I used:
Sub BuildaTableinWordWithExcelData()
Dim myDB As Database
Dim myActiveRecord As Recordset
Dim i As Long
Dim j As Long
Dim dtable As Table, drow As Row
Set myDB = OpenDatabase("C:\myBook1.xls", False, False, "Excel
8.0;HDR=NO")
Set myActiveRecord = myDB.OpenRecordset("mySSRange", dbOpenForwardOnly)
Set dtable = ActiveDocument.Tables.Add(Range:=Selection.Range, _
NumRows:=1, numcolumns:=myActiveRecord.Fields.Count)
Set drow = dtable.Rows(1)
Do While Not myActiveRecord.EOF
For i = 1 To myActiveRecord.Fields.Count
drow.Cells(i).Range.Text = myActiveRecord.Fields(i - 1)
Next i
Set drow = dtable.Rows.Add
myActiveRecord.MoveNext
Loop
drow.Delete
myActiveRecord.Close
myDB.Close
End Sub
When I first ran this code, I got a Runtime error: 94 "Invalid use of
Null" when the code tried to write the label "Age" in the first row. I
suspected that this had something to do with mixed numbers and text in
the column and so I formatted column 2 as "Text" vice the default
"General."
This seems to work, but I was wondering if there was something that I
could put in the code above that would work around this error
automatically to avoid having to specifically set a format?
Thanks.
> Thank you very much.
>
[quoted text clipped - 78 lines]
> >>
> >> Thanks.
PapaDos - 18 Oct 2006 23:31 GMT
Accessing Excel files through a database engine has some limitations.
This is one of them.
If you ONLY need to READ the data, adding ";IMEX=1" to the 4rth parameter
may help:
"Excel 8.0; HDR=NO; IMEX=1;"
This would convert mixed data types columns to text when possible.
But it only looks at a few lines (default is 8, I think) before deciding if
the column contains more than one data type, so this is not much better. And
do not ever try to update or append to the recordset data with this option...

Signature
Regards,
Luc.
"Festina Lente"
> PapaDos,
>
[quoted text clipped - 161 lines]
> > >>
> > >> Thanks.
Greg Maxey - 19 Oct 2006 00:12 GMT
PapaDos,
Thanks for the information. You seem to have a treasure chest of bits to
add to the 4th parameter with which to enlighten the masses. Where can a
list of these be found for reference?
Thanks again.

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
> Accessing Excel files through a database engine has some limitations.
> This is one of them.
[quoted text clipped - 178 lines]
>>>>>
>>>>> Thanks.