Merge-Access spawns copy of access and says DB is locked or in use

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to merge the current record into a document. Word fires up ok,
but when it goes to get the data it spawns a new instance on Access.

The screen flickers and if you can see the error message it is from word who
spawned the new instance of Access and it complains that the DB is locked. Of
course the first instance of Access has the DB opened and the record which I
want to use for the merged document is also open.

The Merge document is a standard word formatted document which I removed the
datasource information from.

Here is the code that drives this merge:

Private Sub Print_Cert_Click()

Rem ** Here we update the number of print in circulation based on the print
size
Rem ** We also create a record in the Photosales Table to show where the
print is going
Dim objWord As Word.Document
Form.AllowEdits = True
DoCmd.OpenForm ("Certificate Entry")
If (DelLocation > 0) Then
Select Case ImSize
Case 1
size = "S"
CirculationSmall = CirculationSmall + 1
mergdoc = "p:\certificate small-mergable.doc"
Case 2
size = "M"
CirculationMedium = CirculationMedium + 1
mergdoc = "p:\certificate medium-merge.doc"
Case 3
size = "L"
CirculationLarge = CirculationLarge + 1
mergdoc = "p:\certificate large-mergable.doc"
Case 4
size = "MC"
CirculationMediumCanvas = CirculationMediumCanvas + 1
mergdoc = "p:\certificate MCmergable.doc"
Case 5
size = "LC"
CirculationLargeCanvas = CirculationLargeCanvas + 1
mergdoc = "p:\certificate LCmergable.doc"
End Select

Certificate.Value = True
InsCMD = "Insert into photosales (resellernumber,PictureNumber,Series)
values (" & DelLocation & "," & PictureNumber & ", '" & size & "' )"
DoCmd.RunSQL InsCMD
Form.Refresh
Form.AllowEdits = False

' **** This is were the merge to Word starts ****
Set objWord = GetObject(mergdoc, "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the photography.mdb database.
objWord.MailMerge.OpenDataSource _
Name:="q:\photography.mdb ", _
LinkToSource:=True, _
Connection:="TABLE Picture_Data", _
SQLStatement:="SELECT Title, PictureDate, Subject_Matter, Location
FROM Picture_Data WHERE (((Picture_Data.PrintCertificate)=-1))"

' Execute the mail merge.
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
Set objWord = Nothing

End If

End Sub
 
Back
Top