PDA

View Full Version : Stop SQL screen prompt



BradleyS
11-03-2011, 04:12 PM
Hi I have a bit of basic code shown below which when I open the document it prints it and closes it and it works fine.
However on some of the documents I have merge fields and I get the following screen prompt appear when it is initially opened:


Opening this document will run the following SQL command:
SELECT * FROM BLAH BLAH BLAH
Data from your database will be placed in this document. Do you wish to continue?

YES or NO

Can I add something to the VB code below to stop this screen prompt or make it press NO?

Sub PrintDefault()
'
' PrintDefault Macro
' Print current document to Default Printer
'

ActiveDocument.PrintOut
ActiveDocument.Saved = True
ActiveDocument.Close
Application.Quit

End Sub

Tommy
11-04-2011, 10:47 AM
Try this, all it does is tell word not to display alerts. Then after the sub runs to display alerts.
Sub PrintDefault()
'
' PrintDefault Macro
' Print current document to Default Printer
'
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.PrintOut
ActiveDocument.Saved = True
ActiveDocument.Close
Application.Quit
Application.DisplayAlerts = wdAlertsAll
End Sub

macropod
11-05-2011, 06:40 AM
Telling Word to not display alerts will stop the mailmerge main document linking to its data source. You'll be able to print the mailmerge main document showing its field coding, though. Just be careful not to save the document in that state - doing so will kill the document's mailmerge function.