wrightyrx7
Registered User.
- Local time
- Today, 13:16
- Joined
- Sep 4, 2014
- Messages
- 104
Hi all,
I have created a tool in Access to generate letters from data in a SQL Server which is working fine.
However, there is 10+ users of this tool and only 1 Word Document on the network drive. I have a problem with the Word Document, SOMETIMES its does not close down properly and I have to close it via task manager (Processes) on the users computer. This stops the tool working for everyone else because someone is in the document.
So what i was thinking is each time the user presses generate it creates a copy of the word document locally, completes the merge, then deletes the copy.
Or maybe someone could look at my code and see if they can spot why sometimes the document doesnt close properly.
I have a FUNCTION for the Save Location as i use if for a few different forms.
I have created a tool in Access to generate letters from data in a SQL Server which is working fine.
However, there is 10+ users of this tool and only 1 Word Document on the network drive. I have a problem with the Word Document, SOMETIMES its does not close down properly and I have to close it via task manager (Processes) on the users computer. This stops the tool working for everyone else because someone is in the document.
So what i was thinking is each time the user presses generate it creates a copy of the word document locally, completes the merge, then deletes the copy.
Or maybe someone could look at my code and see if they can spot why sometimes the document doesnt close properly.
I have a FUNCTION for the Save Location as i use if for a few different forms.
Code:
Private Sub Gen()
Dim MyWord As Word.Application
Dim cType As String
Dim strFileName As String
strFileName = "\\opdeptfs1\test.docx"
wordDoc = SaveLoc(Me.EmpID)
Set MyWord = New Word.Application
With MyWord
.Documents.Open (strFileName)
.ActiveDocument.Bookmarks("FORENAME1").Range.Text = Me.FORENAME
.ActiveDocument.Bookmarks("SURNAME1").Range.Text = Me.SURNAME
.ActiveDocument.SaveAs2 wordDoc, 17
End With
DoEvents
MyWord.Quit savechanges:=wdDoNotSaveChanges
Set MyWord = Nothing
strFileName = ""
wordDoc = ""
MsgBox ("Complete")
End Sub
Function SaveLoc(EmpID As String) As String
With Application.FileDialog(msoFileDialogSaveAs)
.Title = "Save Location for PDF"
.InitialFileName = EmpID
If .Show = True Then
If Right(.SelectedItems(1), 4) = ".pdf" Then
SaveLoc = .SelectedItems(1)
Else
SaveLoc = .SelectedItems(1) & ".pdf"
End If
Else
SaveLoc = ""
End If
End With
End Function