Word document sticks in memory after merge (1 Viewer)

spnz

Registered User.
Local time
Today, 11:16
Joined
Feb 28, 2005
Messages
84
Good afternoon,

I am having some problems with a merge that im doing from a db into word.

The merge works ok but there is after the merge there is always a copy left running.

This is my code.


Code:
Sub PrintContract()


    ''ref word
    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim oDoc As Object
    '''''''''''''''''''''''
    Dim strSaveAs As String
    Dim strPath As String
    Dim strContract As String
    Dim strSQL As String
    Dim strPersonalID As String
    Dim strFileLocation As Variant
    Dim strBookingNumber As String
    Dim strFolderLocation As String '''SQL Statement to insert into tblFileAttachments
    Dim strFileDescription As String
    Dim strComplete As String
    Dim strAddress3 As String
    Dim strAddress4 As String
    Dim strFolderName As String
       
    Dim strLocation As String
    Dim strMyFolder As String

    
    '''Need to chane value if address line 3 & 4 are null
    If IsNull(Forms![frmMain]![txtAddress4]) Then strAddress4 = ""
    If IsNull(Forms![frmMain]![txtAddress3]) Then strAddress3 = ""
    
    Debug.Print Forms![frmMain]![txtAddress4].Value
    Debug.Print strAddress4
    
    
    If IsNull(Forms![frmMain]![fsubBookingDetails].Form![txtJobTitle]) Then
    MsgBox ("You need to have a JOB TITLE to run contract"), vbInformation, "Missing Information"
    Forms![frmMain]![fsubBookingDetails].Form![txtJobTitle].SetFocus
    Forms![frmMain]![fsubBookingDetails].Form![chkContractSent].Value = 0
    End If
    
    If IsNull(Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber]) Then
    MsgBox ("You need to have a BOOKING NUMBER to run contract"), vbInformation, "Missing Information"
    Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].SetFocus
    Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    End If
       
    '''''''''''''''''''''''curPayRate
    If IsNull(Forms![frmMain]![fsubBookingDetails].Form![curPayRate]) Then
    MsgBox ("You need to have a PAY RATE to run contract"), vbInformation, "Missing Information"
    Forms![frmMain]![fsubBookingDetails].Form![curPayRate].SetFocus
    Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    End If
    ''Also need to ensure the payrate is not £0
    If (Forms![frmMain]![fsubBookingDetails].Form![curPayRate]) = "0" Then
    MsgBox ("Sorry but a temp cant be paid £0 per hour"), vbInformation, "Missing Information"
    Forms![frmMain]![fsubBookingDetails].Form![curPayRate].SetFocus
    Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    End If

    '''''''''dtmStartDate
    If IsNull(Forms![frmMain]![fsubBookingDetails].Form![dtmStartDate]) Then
    MsgBox ("You need to have a START DATE to run contract"), vbInformation, "Missing Information"
    Forms![frmMain]![fsubBookingDetails].Form![dtmStartDate].SetFocus
    Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    End If
    '''''''''
    If IsNull(Forms![frmMain]![txtAddress1]) Then
    MsgBox ("You need to have an Address1 to run contract"), vbInformation, "Missing Information"
    Forms![frmMain]![txtAddress1].SetFocus
    Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    End If
    
    If IsNull(Forms![frmMain]![txtAddress2]) Then
    MsgBox ("You need to have an Address2 to run contract"), vbInformation, "Missing Information"
    Forms![frmMain]![txtAddress2].SetFocus
    Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    End If
    
    If IsNull(Forms![frmMain]![txtPostCode]) Then
    MsgBox ("You need to have a POSTCODE to run contract"), vbInformation, "Missing Information"
    Forms![frmMain]![txtPostCode].SetFocus
    Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    End If
  
    ''''autocompletes txtdate
    If Forms![frmMain]![fsubBookingDetails].Form![chkContractSent].Value = -1 Then
    Forms![frmMain]![fsubBookingDetails].Form![chkContractSent].Value = Date
 
    End If

    
     
    
    strFileLocation = "Main Folder"
    strLocation = "G:\Temp Information\"
    strFolderName = CStr([txtTempName])
    strMyFolder = strLocation & strFolderName
    
    
    If Dir(strMyFolder, vbDirectory) = "" Then
    MkDir (strMyFolder)
End If

    
    strBookingNumber = Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber]
    strBookingNumber = Forms![frmMain]![fsubBookingDetails].Form![PersonalID]
    strPath = "G:\Temp Information\"
    strSaveAs = Forms![frmMain]![txtTempName] & " " & Format$(Date, "dd mmm yy") & "\"
    strContract = "Contract" & " " & Format$(Date, "dd_mmm_yy") & ".doc"
    strComplete = strPath & strSaveAs & strContract

    
    ''Before starting code need to check for null values
    
    
    
  
    Set objWord = CreateObject("word.application")
    ''''path of word template
    Set oDoc = objWord.Documents.Add("G:\CTRDD\Templates\contract.doc")
    ''''show the document
    objWord.Visible = False
    
    
    On Error GoTo ErrorTrap
    
   
    strFileDescription = "Contract" & strBookingNumber
    
    DoCmd.Hourglass True
   

''''''''''''''''''''''''''''''''''PART 2
''''''''''''''''''''''''''''''''''''''''
   
    
''''''''''''''

'    On Error Resume Next  ''''use this in case any of the address boxes are null


oDoc.Bookmarks("address1").Select
objWord.Selection.Text = Forms![frmMain]![txtAddress1]

oDoc.Bookmarks("address2").Select
objWord.Selection.Text = Forms![frmMain]![txtAddress2]

oDoc.Bookmarks("address3").Select
objWord.Selection.Text = strAddress3

oDoc.Bookmarks("address4").Select
objWord.Selection.Text = strAddress4

oDoc.Bookmarks("PostCode").Select
objWord.Selection.Text = Forms![frmMain]![txtPostCode]

oDoc.Bookmarks("Jobtitle").Select
objWord.Selection.Text = Forms![frmMain]![fsubBookingDetails].Form![txtJobTitle]

oDoc.Bookmarks("Name").Select
objWord.Selection.Text = Forms![frmMain]![txtTempName]

oDoc.Bookmarks("StartDate").Select
objWord.Selection.Text = Forms![frmMain]![fsubBookingDetails].Form![dtmStartDate]

oDoc.Bookmarks("PayRate").Select
objWord.Selection.Text = CStr(Format(Forms![frmMain]![fsubBookingDetails].Form![curPayRate], "£###.00"))


oDoc.Bookmarks("Today").Select
'objWord.Selection.Text = CStr(Now("dd/mm/yy"))
objWord.Selection.Text = Date

objWord.Visible = False
objWord.PrintOut , , , , , , , 2
'objWord.PrintOut
MsgBox "2 Copies of the contract have now been printed", vbInformation, "Contract Printed"
'oDoc.SaveAs ("G:\Temp Information\" & strSaveAs & strContract)

''''Update tblFileAttachments & create auto link
strFileLocation = ("G:\Temp Information\" & strSaveAs & strContract)
strSQL = "INSERT INTO tblFileAttachments (PersonalID,FileLocation,FileDescription) VALUES ('" & strPersonalID & "','" & strFileDescription & "','" & strFileLocation & "')"
CurrentDb.Execute strSQL



objWord.Quit
Set objWord = Nothing
Set oDoc = Nothing



DoCmd.Hourglass False
    
    Exit Sub
ErrorTrap:
    DoCmd.Hourglass False
    MsgBox Err.Number & ":-" & vbCrLf & Err.Description
    Set objWord = Nothing
    Set oDoc = Nothing
    
   
    
  End Sub

Can anyone see a reason why there is still a copy running?

Thanks for your help.
 

jubb

Registered User.
Local time
Today, 20:16
Joined
Jul 27, 2005
Messages
50
Hi,
I have had a look at your code and changed a bit of it, try it out and see if it works now as the changes are untested. I have been working with alot of Access to Word stuff recently and the code is very similar to something I have just finished working on.

Code:
Sub PrintContract()
    ''ref word
    Dim objWord As Word.Application
    Dim objDoc As Word.Document

    Dim strSaveAs As String
    Dim strPath As String
    Dim strContract As String
    Dim strSQL As String
    Dim strPersonalID As String
    Dim strFileLocation As Variant
    Dim strBookingNumber As String
    Dim strFolderLocation As String '''SQL Statement to insert into tblFileAttachments
    Dim strFileDescription As String
    Dim strComplete As String
    Dim strAddress3 As String
    Dim strAddress4 As String
    Dim strFolderName As String
    Dim strLocation As String
    Dim strMyFolder As String

'arrays to store bookmark information in
'change the values if you need to add more bookmarks
    Dim BMname(10) As String
    Dim BMtext(10) As String
    Dim cntr As Integer
   
    '''Need to chane value if address line 3 & 4 are null
    If IsNull(Forms![frmMain]![txtAddress4]) Then
        strAddress4 = ""
    End If
    If IsNull(Forms![frmMain]![txtAddress3]) Then
        strAddress3 = ""
    End If
    
'    Debug.Print Forms![frmMain]![txtAddress4].Value
'    Debug.Print strAddress4
    
    If IsNull(Forms![frmMain]![fsubBookingDetails].Form![txtJobTitle]) Then
        MsgBox ("You need to have a JOB TITLE to run contract"), vbInformation, "Missing Information"
        Forms![frmMain]![fsubBookingDetails].Form![txtJobTitle].SetFocus
        Forms![frmMain]![fsubBookingDetails].Form![chkContractSent].Value = 0
    ' figure you want to stop processing so the user can change the value
        Exit Sub
    End If
    
    If IsNull(Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber]) Then
        MsgBox ("You need to have a BOOKING NUMBER to run contract"), vbInformation, "Missing Information"
        Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].SetFocus
        Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    ' figure you want to stop processing so the user can change the value
        Exit Sub
    End If
       
    ''curPayRate
    If IsNull(Forms![frmMain]![fsubBookingDetails].Form![curPayRate]) Then
        MsgBox ("You need to have a PAY RATE to run contract"), vbInformation, "Missing Information"
        Forms![frmMain]![fsubBookingDetails].Form![curPayRate].SetFocus
        Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    ' figure you want to stop processing so the user can change the value
        Exit Sub
    End If
    ''Also need to ensure the payrate is not £0
    If (Forms![frmMain]![fsubBookingDetails].Form![curPayRate]) = "0" Then
        MsgBox ("Sorry but a temp cant be paid £0 per hour"), vbInformation, "Missing Information"
        Forms![frmMain]![fsubBookingDetails].Form![curPayRate].SetFocus
        Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    ' figure you want to stop processing so the user can change the value
        Exit Sub
    End If

    ''dtmStartDate
    If IsNull(Forms![frmMain]![fsubBookingDetails].Form![dtmStartDate]) Then
        MsgBox ("You need to have a START DATE to run contract"), vbInformation, "Missing Information"
        Forms![frmMain]![fsubBookingDetails].Form![dtmStartDate].SetFocus
        Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
        ' figure you want to stop processing so the user can change the value
        Exit Sub
    End If
    
    If IsNull(Forms![frmMain]![txtAddress1]) Then
        MsgBox ("You need to have an Address1 to run contract"), vbInformation, "Missing Information"
        Forms![frmMain]![txtAddress1].SetFocus
        Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    ' figure you want to stop processing so the user can change the value
        Exit Sub
    End If
    
    If IsNull(Forms![frmMain]![txtAddress2]) Then
        MsgBox ("You need to have an Address2 to run contract"), vbInformation, "Missing Information"
        Forms![frmMain]![txtAddress2].SetFocus
        Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    ' figure you want to stop processing so the user can change the value
        Exit Sub
    End If
    
    If IsNull(Forms![frmMain]![txtPostCode]) Then
        MsgBox ("You need to have a POSTCODE to run contract"), vbInformation, "Missing Information"
        Forms![frmMain]![txtPostCode].SetFocus
        Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber].Value = 0
    ' figure you want to stop processing so the user can change the value
        Exit Sub
    End If
  
    ''autocompletes txtdate
    If Forms![frmMain]![fsubBookingDetails].Form![chkContractSent].Value = -1 Then
        Forms![frmMain]![fsubBookingDetails].Form![chkContractSent].Value = Date
    End If
    
''Changed you code here
    strFileLocation = "Main Folder"
    strLocation = "G:\Temp Information\"
    strFolderName = CStr([txtTempName])
    strMyFolder = strLocation & strFolderName
    If Dir(strMyFolder, vbDirectory) = "" Then
        MkDir (strMyFolder)
    End If


    strBookingNumber = Forms![frmMain]![fsubBookingDetails].Form![txtBookingNumber]
' think you might want to look at the your next line, perhaps it should be as follows :
    strBookingNumber = strBookingNumber & Forms![frmMain]![fsubBookingDetails].Form![PersonalID]
'instead of:
'    strBookingNumber = Forms![frmMain]![fsubBookingDetails].Form![PersonalID]

    strPath = "G:\Temp Information\"
    strSaveAs = Forms![frmMain]![txtTempName] & " " & Format$(Date, "dd mmm yy") & "\"
    strContract = "Contract" & " " & Format$(Date, "dd_mmm_yy") & ".doc"
    strComplete = strPath & strSaveAs & strContract
    
''Before starting code need to check for null values
'' Checked for Null Values Earlier?????
    Set objWord = CreateObject("word.application")
''''path of word template
    objWord.Documents.Add ("G:\CTRDD\Templates\contract.doc")
''''keep document hidden - faster method of transferring text to bookmarks
    objWord.Visible = False
    
    On Error GoTo ErrorTrap
   
    strFileDescription = "Contract" & strBookingNumber
    
'Store the names of the word bookmarks in an array
    BMname(1) = "address1"
    BMname(2) = "address2"
    BMname(3) = "address3"
    BMname(4) = "address4"
    BMname(5) = "postcode"
    BMname(6) = "JobTitle"
    BMname(7) = "Name"
    BMname(8) = "StartDate"
    BMname(9) = "PayRate"
    BMname(10) = "Today"
    
'store the text for the bookmarks in an array
    BMtext(1) = Forms![frmMain]![txtAddress1]
    BMtext(2) = Forms![frmMain]![txtAddress2]
    BMtext(3) = strAddress3
    BMtext(4) = strAddress4
    BMtext(5) = Forms![frmMain]![txtPostCode]
    BMtext(6) = Forms![frmMain]![fsubBookingDetails].Form![txtJobTitle]
    BMtext(7) = Forms![frmMain]![txtTempName]
    BMtext(8) = Forms![frmMain]![fsubBookingDetails].Form![dtmStartDate]
    BMtext(9) = CStr(Format(Forms![frmMain]![fsubBookingDetails].Form![curPayRate], "£###.00"))
    BMtext(10) = Date
    
    DoCmd.Hourglass True

'transfer the data to word bookamrs
    For cntr = 1 To 10 Step 1
        If objWord.ActiveDocument.Bookmarks.Exists(BMname(cntr)) Then
            objWord.ActiveDocument.Bookmarks(BMname(cntr)).Select
            objWord.Selection.Text = BMtext(cntr)
        End If
    Next

'no need to set objWord.Visible = False again here already done at start of code
'    objWord.Visible = False
    objWord.PrintOut , , , , , , , 2
    strFileLocation = ("G:\Temp Information\" & strSaveAs & strContract)

'if you want to save the document you need to add the following code
'objWord.ActiveDocument.SaveAs (strFileLocation)
    objWord.Quit
    Set objWord = Nothing
    MsgBox "2 Copies of the contract have now been printed", vbInformation, "Contract Printed"

'Update tblFileAttachments & create auto link
    strSQL = "INSERT INTO tblFileAttachments (PersonalID,FileLocation,FileDescription) VALUES ('" & strPersonalID & "','" & strFileDescription & "','" & strFileLocation & "')"
    CurrentDb.Execute strSQL

    DoCmd.Hourglass False
    
    Exit Sub

ErrorTrap:
    DoCmd.Hourglass False
    MsgBox Err.Number & ":-" & vbCrLf & Err.Description
    Set objWord = Nothing
    
End Sub

There are some sections of your code I am not sure about in terms of what you are trying to achieve but I have left them alone.
If it still doesn't work with the new code, try posting your DB on the forums and I will be more than happy to have a look at it for you.

Jubb.
 

spnz

Registered User.
Local time
Today, 11:16
Joined
Feb 28, 2005
Messages
84
Hi Jubb,

Thanks for your reply.

I am not at work at the moment but I will give your code a go tomorrow and let you know how I get on.

Thank you
 

spnz

Registered User.
Local time
Today, 11:16
Joined
Feb 28, 2005
Messages
84
Hi Jubb,

The code runs nicely until it gets right to the end.

I get a messagebox saying "Word is currently printing,Quitting word will cancel all pending jobs.
Do you want to quit word?

How can I avoid this message? and have word print out automatically and close?


Thanks again!!
 

andysgirl8800

Registered User.
Local time
Today, 04:16
Joined
Mar 28, 2005
Messages
166
I happen to have exactly the same problem with my mail merge automation, leaving a copy running. When I go to shut down my system at the end of the day, I'm aked if I want to save changes. If I forget and click "yes" to save the changes, I have to go back in the next day and reset all of my bookmarks again.
I would really like to know if you get this resolved!
 

jubb

Registered User.
Local time
Today, 20:16
Joined
Jul 27, 2005
Messages
50
Hi,

Glad to here the code worked for you.

The only thing I can think of trying off hand would be to move the
Code:
MsgBox "2 Copies of the contract have now been printed", vbInformation, "Contract Printed"

Line to before the objWord.Quit

if that doesn't give word enough time to print out the docs you may need to add a small pause timer loop into your code before you quit
Code:
PTime = 5
Strt = Timer
Do While Timer < Strt + PTime
        DoEvents
Loop
will pause for approx 5 seconds,


hope this fixes the problem for you.

Jubb.
 

spnz

Registered User.
Local time
Today, 11:16
Joined
Feb 28, 2005
Messages
84
Hey Jubb,

Yes your right. I managed to fix it yesterday by moving the messagebox upto where you said.


Sorry forgot to reply.

Thanks for all your help!
 

jubb

Registered User.
Local time
Today, 20:16
Joined
Jul 27, 2005
Messages
50
Glad to hear you figured it out. Sorry about the delay in replying to your post about the printing problem, just been very busy.

Just posting a db here that you may be interested in for doing Access to Word transfers of text, it works for both 1:1 and 1:Many relationships.

Thought you may want to have a look for future reference.

View attachment AccesstoWord.zip

Jubb
 
Last edited:

jubb

Registered User.
Local time
Today, 20:16
Joined
Jul 27, 2005
Messages
50
To andysgirl8800

If your still having the same problem post your code on the forum and I will be more than happy to have a look at it for you. You could also download the zip file I have attached and have a look at how I do access to word transfers.

Jubb
 

andysgirl8800

Registered User.
Local time
Today, 04:16
Joined
Mar 28, 2005
Messages
166
Thanks for replying. The firewalls on my work PC don't allow me to download zipped files- a very frustrating little detail here. I've pasted my code below. Hopefully, you can offer some insight! Thanks so much for your help!
______________________________________________
Private Sub Print_Medical_Necessity_Click()

Dim objWord As Word.Application
'Start Microsoft Word 2000.
Set objWord = CreateObject("Word.Application")

With objWord
'Make the application visible.
.Visible = False



'Open the document.
.Documents.Open ("G:\Pharmacy\Prior Auth Docs and Data\Revised Pharmacy Denial Processes\KAR Sci Clin Judgement.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("bmkFirstName").Select
.Selection.Text = (CStr(Forms!frmDenial!MBRFirst))

.ActiveDocument.Bookmarks("bmkMoreInfo").Select
.Selection.Text = (CStr(Forms!frmDenial!MoreInfo))

.ActiveDocument.Bookmarks("bmkLastName").Select
.Selection.Text = (CStr(Forms!frmDenial!MBRLast))

.ActiveDocument.Bookmarks("bmkHRN").Select
.Selection.Text = (CStr(Forms!frmDenial!MemberNumber))

.ActiveDocument.Bookmarks("bmkAddress1").Select
.Selection.Text = (CStr(Forms!frmDenial!MBRAddress1))

.ActiveDocument.Bookmarks("bmkCity").Select
.Selection.Text = (CStr(Forms!frmDenial!MBRCity))

.ActiveDocument.Bookmarks("bmkState").Select
.Selection.Text = (CStr(Forms!frmDenial!MBRState))

.ActiveDocument.Bookmarks("bmkZip").Select
.Selection.Text = (CStr(Forms!frmDenial!ZipCode))

.ActiveDocument.Bookmarks("bmkDrug").Select
.Selection.Text = (CStr(Forms!frmDenial!DrugName2))

.ActiveDocument.Bookmarks("bmkStrength").Select
.Selection.Text = (CStr(Forms!frmDenial!Strength))

.ActiveDocument.Bookmarks("bmkDate").Select
.Selection.Text = (CStr(Forms!frmDenial!DateReceivedbyPlan))

.ActiveDocument.Bookmarks("bmkMDFirst").Select
.Selection.Text = (CStr(Forms!frmDenial!MDNameFirst))

.ActiveDocument.Bookmarks("bmkMDLast").Select
.Selection.Text = (CStr(Forms!frmDenial!MDLastName2))

.ActiveDocument.Bookmarks("bmkMDCred").Select
.Selection.Text = (CStr(Forms!frmDenial!Credential))

.ActiveDocument.Bookmarks("bmkFirstName2").Select
.Selection.Text = (CStr(Forms!frmDenial!MBRFirst))

.ActiveDocument.Bookmarks("bmkLastName2").Select
.Selection.Text = (CStr(Forms!frmDenial!MBRLast))

.ActiveDocument.Bookmarks("bmkReason").Select
.Selection.Text = (CStr(Forms!frmDenial!Reason))

.ActiveDocument.Bookmarks("bmkReason2").Select
.Selection.Text = (CStr(Forms!frmDenial!Reason2))

.ActiveDocument.Bookmarks("bmkAlt").Select
.Selection.Text = (CStr(Forms!frmDenial!alternative))

.ActiveDocument.Bookmarks("bmkMDFirst2").Select
.Selection.Text = (CStr(Forms!frmDenial!MDNameFirst))

.ActiveDocument.Bookmarks("bmkMDLast2").Select
.Selection.Text = (CStr(Forms!frmDenial!MDLastName2))

.ActiveDocument.Bookmarks("bmkMDCred2").Select
.Selection.Text = (CStr(Forms!frmDenial!Credential))

.ActiveDocument.Bookmarks("bmkFirstName3").Select
.Selection.Text = (CStr(Forms!frmDenial!MBRFirst))

.ActiveDocument.Bookmarks("bmkLastName3").Select
.Selection.Text = (CStr(Forms!frmDenial!MBRLast))

.ActiveDocument.Bookmarks("bmkAddress11").Select
.Selection.Text = (CStr(Forms!frmDenial!MBRAddress1))

.ActiveDocument.Bookmarks("bmkCity2").Select
.Selection.Text = (CStr(Forms!frmDenial!MBRCity))

.ActiveDocument.Bookmarks("bmkState2").Select
.Selection.Text = (CStr(Forms!frmDenial!MBRState))

.ActiveDocument.Bookmarks("bmkZip2").Select
.Selection.Text = (CStr(Forms!frmDenial!ZipCode))

.ActiveDocument.Bookmarks("bmkMDFirst3").Select
.Selection.Text = (CStr(Forms!frmDenial!MDNameFirst))

.ActiveDocument.Bookmarks("bmkMDLast3").Select
.Selection.Text = (CStr(Forms!frmDenial!MDLastName2))

.ActiveDocument.Bookmarks("bmkMDCred3").Select
.Selection.Text = (CStr(Forms!frmDenial!Credential))

.ActiveDocument.Bookmarks("bmkMDAddress1").Select
.Selection.Text = (CStr(Forms!frmDenial!MDAddress1))

.ActiveDocument.Bookmarks("bmkMDCity").Select
.Selection.Text = (CStr(Forms!frmDenial!MDCity))

.ActiveDocument.Bookmarks("bmkMDState").Select
.Selection.Text = (CStr(Forms!frmDenial!MDState))

.ActiveDocument.Bookmarks("bmkMDZip").Select
.Selection.Text = (CStr(Forms!frmDenial!MDZip))
End With

MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next

End If
objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
objWord.Application.PrintOut Range:=wdPrintRangeOfPages, Pages:="2,3,4,5,6,7"
objWord.Application.PrintOut Range:=wdPrintRangeOfPages, Pages:="2,3,4,5,6,7"
ActiveDocument.Close wdDoNotSaveChanges
Exit Sub

End Sub
 

jubb

Registered User.
Local time
Today, 20:16
Joined
Jul 27, 2005
Messages
50
Hi andysgirl8800

try changing the end of your code to
Code:
objWord.Application.Options.PrintBackground = False
objWord.PrintOut , , , , , , , , "2,3,4,5,6,7"
objWord.Quit False
Set objWord = Nothing
Exit Sub

I tried it doing this at home and it worked the way I think you want.

Hope this helps.

Jubb.
 

andysgirl8800

Registered User.
Local time
Today, 04:16
Joined
Mar 28, 2005
Messages
166
That worked a charm!! Thanks so much for your help. Had been struggling with that one for months. Silly how it takes just a little wording change to fix it all! Thanks again.
 

Users who are viewing this thread

Top Bottom