View Single Post
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
[email protected] amrnorman@cox.net is offline
external usenet poster
 
Posts: 2
Default Word 2003 - VB Code Does not work like it did in Word 2000

Hello,

I created an Access 2000 database that opens up Word 2000 documents for
merging. Within the Word 2000 document version is the following code.
It pulls records from the Access database based upon the record
creation date and a "typist" field. It works like a charm in 2000, but
when it runs from 2003 the message that no records were found displays.
Please help! Thanks.

Private Sub Document_Open()

Dim CreationDate As Variant, Initials As Variant, ErrorNumber As Long

Do

CreationDate = InputBox("Please enter the letter creation date below:"
& vbCrLf & _
vbCrLf & "Date Format: mm/dd/yy", "Und23 Letter - Input Required")
If IsNull(CreationDate) Then Exit Sub

Initials = InputBox("Please enter your initials below:", "Und23 Letter
- Input Required")
If IsNull(Initials) Then Exit Sub


On Error Resume Next

ActiveDocument.MailMerge.DataSource.QueryString = _
"SELECT * FROM [Und23] WHERE (([CreateDate] = #" & CreationDate
& "#) AND ([Typist] = " & Chr(34) & Initials & Chr(34) & "))"

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = False
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=True

End With

ErrorNumber = Err.Number

If ErrorNumber 0 Then
If MsgBox("There were no records that matched your search criteria.
Do you want to try again?", vbQuestion Or vbYesNo, "No records found")
= vbNo Then
ErrorNumber = 0
End If
Else
ThisDocument.Close SaveChanges:=wdDoNotSaveChanges
End If
On Error GoTo 0

Loop Until ErrorNumber = 0

End Sub