check for presence of data source

M

mikeiastat

I am trying to automate printing a mailmerge without any user intervention.
My database software outputs a .CSV file whenever it has data that meets the
correct criteria. This data file is not always going to be out on the drive
because there are many days that there are no results.

Word pops up the message box "Word cannot find data Source" when the file is
not there. I would like to handle this in my merge with some macro code, so
that I don't have to deal with the program on a day to day basis. However, I
would like to do this within Word if at all possible. I don't wan't to have
to have a separate script that checks for the file and then calls Word and
the merge.

Thanks in advance
 
D

Doug Robbins - Word MVP

I would be looking at a way to do this from within the database, probably
not using Word at all, but a report in the database.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

mikeiastat

The word merges are delivered from the vendor and are already done. Except I
want to automate them. It would take months of programming to do over 100
different letter types within the database reporting.

This error message is the only obstacle I have left to do to eliminate all
that coding. If I can do it gracefully with a macro all I have to do is set
up the shortcuts to point to the right letter template and then schedule them.

I have the rest taken care of and this wroute, if possible would save us
lots of time and money. Give our current resources, I don't know that we
would develop it inside the database reporting. The other option at this
point is to have someone manually open the files and do the merge to printer
for only the files that have data.

Doesn't there have to be a way to get this done?
 
D

Doug Robbins - Word MVP

I don't doubt that what you want to do can be done, but you do not give
enough information to be able to point you in the right direction.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

mikeiastat

What else do you need to know.

If I wasn't clear, I have a peoplesoft process that runs and batches records
that need a letter sent out. Some days each of the process may not have any
data and therefor Peoplesoft does not put out an output file. I would like
to schedule a widows scheduler to run every morning with a word file. The
word file has a macro that is set up to run automatically and Print the
letters for me.

The problem is that before it runs the macro that prints the letters and
backs up the datafile, I get this error message that read something like -
Word cannot find the Data Source.

I have to get past the error message before the macro can run, so I can't
put the code in the macro to handle the exception of not having a datafile
for the merge to run with.

I just want to exit word if there is no datafile present.
 
D

Doug Robbins - Word MVP

If you try to open a file that does not exist, you will get a 5174 error
message. There for put the following at the beginning of your code,
replacing the drive:\path\filename in the example with the filename of the
datasource

Dim adoc As Document
On Error GoTo ErrorHandler
Set adoc = Documents.Open("C:\test\text.doc")

ErrorHandler:
If Err.Number = 5174 Then
Exit Sub
End If

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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