Really Irritating me now!

Haynesey

Registered User.
Local time
Today, 14:55
Joined
Dec 19, 2001
Messages
190
I am using the following VB code to open a mailmerged document and print it. This worked fine until we had to allow more users access to the database. We then thought it would be best to hide the database window so that nobody could mess things up. However, due to this, the mail merge code doesn't work?

Any ideas?
Thanks in advance
Lee

Dim objWord As Word.Document
Set objWord = GetObject("J:\Admin\ISES\P_CapitaBookingForm.dot", "Word.Document")

' Make Word visible.
objWord.Application.Visible = True

' Set the mail merge data source
objWord.MailMerge.OpenDataSource Name:="J:\Admin\ISES\ISES.mdb", _
LinkToSource:=True, _
Connection:="Query qryCourseBookingMailMerge"

objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute

'The following line must follow the Execute statement because the PrintBackground property is available only when a document window is active. Without this line of code, the function will end before Word can print the merged document.

objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
 
You can use the following to unhide the window before action and then use it to rehide the window...

Function HideDatabaseWindow(bHide As Boolean) As Boolean
' Comments : Hides or shows the database window
' Parameters: bHide - true to hide the database window, false to un-hide it
' Returns : True if successful, False otherwise
'
Const c_intForm = 0
Const c_intWindow = 4
Const c_intHide = 3
Const c_intUnHide = 4

On Error GoTo err_HideDatabaseWindow

' Move focus to the window
DoCmd.SelectObject acTable, "", True

' Use the window menu to hide or show the database window
If bHide Then
DoCmd.DoMenuItem c_intForm, c_intWindow, c_intHide, , acMenuVer20
Else
DoCmd.DoMenuItem c_intForm, c_intWindow, c_intUnHide, , acMenuVer20
End If

HideDatabaseWindow = True

exit_HideDatabaseWindow:
Exit Function

err_HideDatabaseWindow:
HideDatabaseWindow = False
Resume exit_HideDatabaseWindow

End Function
 

Users who are viewing this thread

Back
Top Bottom