LarryDeLaruelle
Technical User
I am setting up a merge routine in Access to merge selected data to a Word form. The form was created as a mailmerge and linked to a table in Access (the database uses Access security).
On a form, the user selects the record to merge and clicks on a command button to initiate the merge. The merge process runs a make table query for the selected record, opens the word document (prompts twice for UserID/Password??) then merges the data into the document. So far so good.
If I then try to run the merge for another record, I get the run time error 3262 -- "Couldn't lock table 'tblWordMerge'; currently in use by . . . ". I have figured out that this is because of the iteration of the database that was opened for the merge -- if I close that, the merge will work fine.
Here is the code I have so far:
Dim objWord As Word.Document
Dim strSQL As String
strSQL = "SELECT Client.ClientID, Client.FullName, Client.DOB, DateDiff('d',[dob],Date())\365 AS Age, "
strSQL = strSQL & "Client.Sex, Client.OaklawnNum, Client.SocialSecurityNum, Race.Race, "
strSQL = strSQL & "Client.CurrentStatusID INTO tblWordMerge "
strSQL = strSQL & "FROM Client INNER JOIN Race ON Client.RaceID = Race.RaceID "
strSQL = strSQL & "WHERE (((Client.OaklawnNum) = '" & Me.OaklawnNum & "') And ((Client.CurrentStatusID) = 2)); "
DoCmd.SetWarnings False
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings True
Set objWord = GetObject("G:\Database\TCC Reports\AccessMergeTest.Doc", "Word.Document"
'Prompts for log on twice at this line.
objWord.MailMerge.Execute
Set objWord = Nothing
Is there a way I can, in code, close that extra iteration of Access that is locking the merge table? Or, is there a way I can release the lock on the table?
When this is done, I want to be able to merge the information in tblWordMerge to a number of different documents as well as run the merge for a number of records.
Thanks.
Larry De Laruelle
On a form, the user selects the record to merge and clicks on a command button to initiate the merge. The merge process runs a make table query for the selected record, opens the word document (prompts twice for UserID/Password??) then merges the data into the document. So far so good.
If I then try to run the merge for another record, I get the run time error 3262 -- "Couldn't lock table 'tblWordMerge'; currently in use by . . . ". I have figured out that this is because of the iteration of the database that was opened for the merge -- if I close that, the merge will work fine.
Here is the code I have so far:
Dim objWord As Word.Document
Dim strSQL As String
strSQL = "SELECT Client.ClientID, Client.FullName, Client.DOB, DateDiff('d',[dob],Date())\365 AS Age, "
strSQL = strSQL & "Client.Sex, Client.OaklawnNum, Client.SocialSecurityNum, Race.Race, "
strSQL = strSQL & "Client.CurrentStatusID INTO tblWordMerge "
strSQL = strSQL & "FROM Client INNER JOIN Race ON Client.RaceID = Race.RaceID "
strSQL = strSQL & "WHERE (((Client.OaklawnNum) = '" & Me.OaklawnNum & "') And ((Client.CurrentStatusID) = 2)); "
DoCmd.SetWarnings False
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings True
Set objWord = GetObject("G:\Database\TCC Reports\AccessMergeTest.Doc", "Word.Document"
'Prompts for log on twice at this line.
objWord.MailMerge.Execute
Set objWord = Nothing
Is there a way I can, in code, close that extra iteration of Access that is locking the merge table? Or, is there a way I can release the lock on the table?
When this is done, I want to be able to merge the information in tblWordMerge to a number of different documents as well as run the merge for a number of records.
Thanks.
Larry De Laruelle