Trapping error code 5631

A

APH

Hi,

Apologies if this appears twice - not sure if I hit the send button properly
first tyime

Ok, I have a Word document which uses predefined query to supply data for
Mail-merge. The trigger for this is a button with Access, and I use the
code below to launch the Word document .

However if there are no records in the Access query, I need to trap error
code 5631 (I believe) and then drop out of the function. Should I do this
as a separate function before I use the code below, or can it be done within
the code below?

many thanks

Alex


' Opens a word doc in mail merge mode 04/12/03

Dim WordApp As Object
Dim WordDoc As Object
Dim strDocName As String
clsPBar.ShowProgress
clsPBar.TextMsg = "Launching Microsoft Word...please wait..."

On Error GoTo CreateWordApp
Set WordApp = GetObject(, "Word.Application")
On Error GoTo 0

Set WordDoc = WordApp.Documents.Open(strWordDoc)
WordApp.Visible = True

AppActivate "Microsoft Word"
WordApp.WindowState = 0 'wdWindowStateRestore

clsPBar.HideProgress

Exit Function

CreateWordApp:

Set WordApp = CreateObject("Word.Application")
Resume Next
 
K

Ken Snell

I don't see in your code example where you're running a query? However, why
not use the DCount function to determine if your query has any records, and
if yes, then run the code that opens Word, etc.:

If DCount("*", "QueryName") > 0 Then
' the query has at least one record
' so put your code here for opening
' Word, etc.
End If
 

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