Hi again - With the help of a post in the VB forum, I have created the following code to automatically launch word and run a mail merge. The problem is that I get an error message opening up the mdb database, stating that it's locked by another user.
How do I force the mail merge to open in read-only? Alternatively, I got the mail merge to work using a query against the table instead of opening the table itself, but I can'f figure out how to update this code to call a query. I thought I could just change to table name to a query name, but that gives me an 'application defined error'
Can anyone help??? Please?
Private Sub Preview_Report_Click()
On Error GoTo Err_merge_Click
'Developed by Robert Sang for Connect Learning Centres 2003
'Load the mail merge document as an object
Dim objWord As Object
Set objWord = GetObject("C:\ABC\Labels_Blank.doc", "Word.Document")
'Make Word visible
objWord.Application.Visible = True
'Open the mail merge data source (this database and record)
objWord.MailMerge.OpenDataSource _
Name:="C:\Personal_Chef\Label.mdb", _
LinkToSource:=True, _
Connection:="TBLabels", _
SQLStatement:="SELECT * FROM [TBLabels] "
'Execute the mail merge
objWord.MailMerge.Execute
Exit_merge_Click:
Exit Sub
Err_merge_Click:
MsgBox Err.Description
Resume Exit_merge_Click
End Sub
How do I force the mail merge to open in read-only? Alternatively, I got the mail merge to work using a query against the table instead of opening the table itself, but I can'f figure out how to update this code to call a query. I thought I could just change to table name to a query name, but that gives me an 'application defined error'
Can anyone help??? Please?
Private Sub Preview_Report_Click()
On Error GoTo Err_merge_Click
'Developed by Robert Sang for Connect Learning Centres 2003
'Load the mail merge document as an object
Dim objWord As Object
Set objWord = GetObject("C:\ABC\Labels_Blank.doc", "Word.Document")
'Make Word visible
objWord.Application.Visible = True
'Open the mail merge data source (this database and record)
objWord.MailMerge.OpenDataSource _
Name:="C:\Personal_Chef\Label.mdb", _
LinkToSource:=True, _
Connection:="TBLabels", _
SQLStatement:="SELECT * FROM [TBLabels] "
'Execute the mail merge
objWord.MailMerge.Execute
Exit_merge_Click:
Exit Sub
Err_merge_Click:
MsgBox Err.Description
Resume Exit_merge_Click
End Sub