H
hals_left
Hi, I am getting a couple of intermittent bugs using a mailmerge
template that has VBA behind.
I created a Word template that links to a data source which defines a
very small SQL View returning a single integer, over a VPN, just enough
to define the connection parameters username password etc.
1) As the user creates a new doc from the template, it promts to run
the SQL on some machines. Is there a way to prevent this prompt on
Windows 2000/XP ?
The user then presses Ctrl-> T to run the following Macro, which is in
Module1
Sub showDialog()
frmDialog.txtFocus.Text = ""
frmDialog.CheckBox1.Value = False
frmDialog.txtFocus.SetFocus
frmDialog.Show
End Sub
The user enters a record ID and the Button calls the code below to
bring a small set of data onto the client.
Private Sub cmdCreate_Click()
On Error Resume Next
Dim strSQL
If IsNumeric(txtFocus.Value) Then
frmDialog.Hide
strSQL = "SELECT * FROM ""MyView"" WHERE ""RecordID""=" &
txtFocus.Value
ActiveDocument.MailMerge.DataSource.QueryString = strSQL
If CheckBox1.Value = True Then
Dialogs(wdDialogMailMergeRecipients).Show
Else
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
If Err.Number <> 0 Then
MsgBox Err.Number & Err.Description, vbOKOnly,
"Mail Merge Error"
End If
End With
End If
Else
MsgBox ("Please enter a valid Record ID")
txtFocus.Text = ""
txtFocus.SetFocus
End If
End Sub
2) If I omit the line "Dialogs(wdDialogMailMergeRecipients).Show"
(Which was added as a workaround) the mailmerge fails saying "Invalid
Merge Field" for every record. Word is only identifying the fields in
the initial Small View, not the data that has been retrieved by the
user. But after cancelling all the warnings, If I select to view
"MailMerge Recipients" manually, it does show the data has been
retrieved.
3) When I run the "Merge to new document" the first page in the
mailmerge has no data. I can fix this by clicking "Last Record" and
then "First Record" before doing the mail merge.
4) In the template under "This document" I added this code. But I still
get prompted to save both the Template and the Letters produced, is
there a way to prevent prompts to save both docs?
Private Sub Document_New()
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.Saved = True
End Sub
Users have Windows XP Pro 2002 SP2 & Word 2002 (10.42.19) SP2
Any help on these issues appreciated
Thanks!
hals_left
template that has VBA behind.
I created a Word template that links to a data source which defines a
very small SQL View returning a single integer, over a VPN, just enough
to define the connection parameters username password etc.
1) As the user creates a new doc from the template, it promts to run
the SQL on some machines. Is there a way to prevent this prompt on
Windows 2000/XP ?
The user then presses Ctrl-> T to run the following Macro, which is in
Module1
Sub showDialog()
frmDialog.txtFocus.Text = ""
frmDialog.CheckBox1.Value = False
frmDialog.txtFocus.SetFocus
frmDialog.Show
End Sub
The user enters a record ID and the Button calls the code below to
bring a small set of data onto the client.
Private Sub cmdCreate_Click()
On Error Resume Next
Dim strSQL
If IsNumeric(txtFocus.Value) Then
frmDialog.Hide
strSQL = "SELECT * FROM ""MyView"" WHERE ""RecordID""=" &
txtFocus.Value
ActiveDocument.MailMerge.DataSource.QueryString = strSQL
If CheckBox1.Value = True Then
Dialogs(wdDialogMailMergeRecipients).Show
Else
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
If Err.Number <> 0 Then
MsgBox Err.Number & Err.Description, vbOKOnly,
"Mail Merge Error"
End If
End With
End If
Else
MsgBox ("Please enter a valid Record ID")
txtFocus.Text = ""
txtFocus.SetFocus
End If
End Sub
2) If I omit the line "Dialogs(wdDialogMailMergeRecipients).Show"
(Which was added as a workaround) the mailmerge fails saying "Invalid
Merge Field" for every record. Word is only identifying the fields in
the initial Small View, not the data that has been retrieved by the
user. But after cancelling all the warnings, If I select to view
"MailMerge Recipients" manually, it does show the data has been
retrieved.
3) When I run the "Merge to new document" the first page in the
mailmerge has no data. I can fix this by clicking "Last Record" and
then "First Record" before doing the mail merge.
4) In the template under "This document" I added this code. But I still
get prompted to save both the Template and the Letters produced, is
there a way to prevent prompts to save both docs?
Private Sub Document_New()
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.Saved = True
End Sub
Users have Windows XP Pro 2002 SP2 & Word 2002 (10.42.19) SP2
Any help on these issues appreciated
Thanks!
hals_left