Word 2003 Macro

F

fasuser

When I try to insert database and select a comma separted file, it inserts
file in table format. But if I record all the steps for above action and try
to run that macro, it is giving me following error:

This operation cannot be completed because of dialog or database engine
failures. Please try again later.

Run-time error '5922':

Word was unable to open the data source.

The code that is giving error is :
With Selection
.Collapse Direction:=wdCollapseEnd
.Range.InsertDatabase _
Style:=0, _
LinkToSource:=False, Connection:="Entire Spreadsheet", _
DataSource:="file.dat"
End With

Any Help,
Thanks,
PS: Above macro works fine with MS Word 2000.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?ZmFzdXNlcg==?=,

I've never had much luck with InsertDatabase, and there are lots of complaints
about it not working. FWIW, the default connection method changed in Word 2002
(from Word's internal converter or ODBC for text files to OLE DB). And often
when Word makes the connection, it creates an additional .odc file where some
information is saved (instead of in the document).

My recommendation would be to
- insert a database field connected to this text file, manually
- Alt+F9 to see the database field code
- use the Fields.Add method to create the database field, directly

You might also want to try another connection method than OLEDB. For this,
activate "Confirm conversions on open" in Tools/Options/General before
inserting the database field. Now, once you've selected the file to open,
you'll get a list of methods to choose from.
When I try to insert database and select a comma separted file, it inserts
file in table format. But if I record all the steps for above action and try
to run that macro, it is giving me following error:

This operation cannot be completed because of dialog or database engine
failures. Please try again later.

Run-time error '5922':

Word was unable to open the data source.

The code that is giving error is :
With Selection
.Collapse Direction:=wdCollapseEnd
.Range.InsertDatabase _
Style:=0, _
LinkToSource:=False, Connection:="Entire Spreadsheet", _
DataSource:="file.dat"
End With

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top