I have almost completed my database and one of my last steps was to split the database and test it on another computer. Every feature works except for the mail merge feature. The mail merge code works fine when the front end and back end of the database are on the same machine but after I loaded my front end database onto my laptop, it can't open the data source (a query) to complete the merge. I did not use the Windows homegroup feature; I just shared the folder the database files are in. I can view and open the files on my laptop with no problem, I can run all the queries and forms of my database with no problems, I just can't get the merge to run.
In the following code, the variable "pathname" is C:\users\david\documents\database files on the machine where the back end resides; "pathname" is \\wks0\users\david\documents\database files on my laptop. The computer with the back end database on it is named wks0.
Code:
Private Sub cmdMerge_Click()' opens Microsoft Word to create a Mail merge letter
On Error GoTo Err_CmdMerge_Click
Dim objWord As New Word.Application
Dim objDoc As Word.Document
Dim Docpath As String
Dim DBpath As String
Dim pathname As Variant
pathname = DLookup("[docpath]", "Files_settings")
DoCmd.RunCommand acCmdAppMinimize
objWord.Application.visible = True
Docpath = pathname & "\GOMOC letter.docx"
DBpath = pathname & "\Gomoc database.accdb"
Set objDoc = objWord.Documents.Open(Docpath)
objWord.WindowState = wdWindowStateMaximize
If Err.number <> 0 Then
Set objWord = CreateObject("Word.Application")
End If
With objDoc.MailMerge
.MainDocumentType = wdFormLetters
.ShowWizard InitialState:=2
.OpenDataSource DBpath, sqlstatement:="SELECT * FROM [Mail Merge Query]", OpenExclusive:=False
'.Execute If you add this line, it completes the mail merge and opens a new word docuement with all the letters in it
End With
objWord.Documents(Docpath).Activate
Set objWord = Nothing
Set objDoc = Nothing
Exit_Err_CmdMerge_Click:
Exit Sub
Err_CmdMerge_Click:
MsgBox Err.Description
Resume Exit_Err_CmdMerge_Click
End Sub
When I try to run the code I get an error that says "Could not find file '\\wks0\users\david\documents\database files.mdb'
Any ideas?