OK here is my situation I have an Access Database that I store demographic and financial information about a client. I then have several queries that will export the data into CSV files saved into a folder with the clients name.
I then have the below code that will look in a folder for the specific word document the user wants to print and the folder the CSV file is stored. I merge the two and save the file in the folder for the client. This works for the most part but on occasions I get and error that word has to be restarted. The Module Name is mso.dll (Version 10.6626.0) I have read that I need to make sure the ~filename.doc files need to be deleted, which I have done, that did not seem to help.
If I open word and open the file I saved it opens just file, I only get the crash when I am creating the file, or when I close the file.
Any ideas?
myView is passed when the user click on the button. 2 is for print preview and 1 is to send it to the printer.
Here is my Code:
I then have the below code that will look in a folder for the specific word document the user wants to print and the folder the CSV file is stored. I merge the two and save the file in the folder for the client. This works for the most part but on occasions I get and error that word has to be restarted. The Module Name is mso.dll (Version 10.6626.0) I have read that I need to make sure the ~filename.doc files need to be deleted, which I have done, that did not seem to help.
If I open word and open the file I saved it opens just file, I only get the crash when I am creating the file, or when I close the file.
Any ideas?
myView is passed when the user click on the button. 2 is for print preview and 1 is to send it to the printer.
Here is my Code:
Code:
myDocumentPath = "R:\SBA Documents"
'Get the SBA Name
myFolderName = Me.cmbLoan.Column(1)
'Remove any special characters and replce with an
'underscore _ also change to uppercase
myFolderName = Replace(myFolderName, ",", "")
myFolderName = Replace(myFolderName, ".", "")
myFolderName = Replace(myFolderName, "&", "")
myFolderName = Replace(myFolderName, "-", "_")
myFolderName = Replace(myFolderName, " ", " ")
myFolderName = Replace(myFolderName, " ", "_")
myFolderName = UCase(myFolderName)
'Determine if it exists
If Dir(myDocumentPath & "\" & myFolderName, vbDirectory) = "" Then
MkDir myDocumentPath & "\" & myFolderName
End If
'504 Eligibility ChecklistA
If Me.ckbEligibility1 = -1 Then
myDocName = myDocumentPath & "\" & myFolderName & "\504 Eligibility ChecklistA.doc"
myDataSource = myDocumentPath & "\" & myFolderName & "\tmp_Submission.csv"
myTemplateName = myTemplatePath & "\504 Eligibility ChecklistA.doc"
Set oApp = GetObject(myTemplateName, "Word.Document")
'oApp.Application.Visible = True
oApp.MailMerge.OpenDataSource Name:=myDataSource, LinktoSource:=True, AddToRecentFiles:=False
oApp.MailMerge.Destination = wdSendToNewDocument
oApp.MailMerge.SuppressBlankLines = True
oApp.MailMerge.Execute
oApp.Application.Documents(1).SaveAs (myDocName)
If myView = 2 Then
oApp.Application.Visible = True
oApp.Close SaveChanges:=wdDoSaveChanges
Else
oApp.Application.ActiveDocument.PrintOut
oApp.Application.Documents(1).Close
End If
Set oApp = Nothing
End If