I am currently having some problems. I have moved an Access 97 application from windows NT to windows 2000. I have some mail merge data that are temporarily created by a query, before being dumped to a word document. Now when the query is called, I get the following message "Cannot update. Database or Object is read only"
Below is the code that is run before the mailmerge document is called.
Private Sub PrintLetter(LetterTemplate As String, UsePrinter As String)
Dim db As Database
Dim rstsys As Recordset
Dim rstMerge As Recordset
Dim qdf As QueryDef
Set db = CurrentDb
Set rstsys = db.OpenRecordset("tblsys", , dbReadOnly)
rstsys.MoveFirst
' Display status form
glrstatus "Printing Document", "Please Wait"
Set qdf = db.CreateQueryDef("", "DELETE * FROM tblMailItems")
' Execute QueryDef.
qdf.Execute
Set rstMerge = db.OpenRecordset("tblMailItems")
rstMerge.AddNew
rstMerge!Surname = Forms!frmapplypost.Surname
rstMerge!Title = Forms!frmapplypost.Title
rstMerge!Initials = Forms!frmapplypost.Initials
rstMerge!Address1 = Forms!frmapplypost.Address1
rstMerge!Address2 = Forms!frmapplypost.Address2
rstMerge!Address3 = Forms!frmapplypost.Address3
rstMerge!Address4 = Forms!frmapplypost.Address4
rstMerge!Address5 = Forms!frmapplypost.Address5
rstMerge!Address6 = Forms!frmapplypost.Address6
If Not Forms!frmapplypost.PostCode = "Unknown" Then
rstMerge!PostCode = Forms!frmapplypost.PostCode
End If
rstMerge!ApplicantID = Forms!frmapplypost.ApplicantID
rstMerge!PostNumber = Forms!frmapplypost!sbfPostApp.Form!PostNumber
rstMerge!PostTitle = Forms!frmapplypost!sbfPostApp.Form!PostTitle
rstMerge!DateAppReturned = Forms!frmapplypost!sbfPostApp.Form!DateAppReturned
rstMerge!ClosingDate = Forms!frmapplypost!sbfPostApp.Form!ClosingDate
rstMerge!DisclosureText = Forms!frmapplypost!sbfPostApp.Form!DisclosureLevel.Column(2)
rstMerge!Selected = True
rstMerge.UPDATE
rstMerge.Close
'if local report then run else mail merge to word
If Not Me.cbodocument.Column(3) = "" Then
Select Case Left(Me.cbodocument.Column(3), 3)
Case "rpt"
printreport Me.cbodocument.Column(3)
Case "qry"
If Nz(DCount("*", Me.cbodocument.Column(3))) = 0 Then
glrstatus
MsgBox "Nothing to print or details incomplete"
Exit Sub
End If
'export table to rtf format with random file name
ExportMergeData Me.cbodocument.Column(3), rstsys!documentpath, LetterTemplate & ".dot", rstsys!templatepath, 0, UsePrinter, 0, LetterTemplate & Format(Date, "yyyymmdd") & ".doc"
rstsys.Close
Case Else
End Select
Else
'export table to rtf format with random file name
Dim intPrint As Integer
If IsNull(UsePrinter) Or UsePrinter = "" Then
intPrint = 1
Else
intPrint = 2
End If
If Nz(DCount("*", "tblMailItems")) = 0 Then
glrstatus
MsgBox "Nothing to print or details incomplete"
Exit Sub
End If
ExportMergeData "tblMailItems", rstsys!documentpath, LetterTemplate & ".dot", rstsys!templatepath, intPrint, UsePrinter, 0, LetterTemplate & Format(Date, "yyyymmdd") & ".doc"
End If
glrstatus
End Sub
Below is the code that is run before the mailmerge document is called.
Private Sub PrintLetter(LetterTemplate As String, UsePrinter As String)
Dim db As Database
Dim rstsys As Recordset
Dim rstMerge As Recordset
Dim qdf As QueryDef
Set db = CurrentDb
Set rstsys = db.OpenRecordset("tblsys", , dbReadOnly)
rstsys.MoveFirst
' Display status form
glrstatus "Printing Document", "Please Wait"
Set qdf = db.CreateQueryDef("", "DELETE * FROM tblMailItems")
' Execute QueryDef.
qdf.Execute
Set rstMerge = db.OpenRecordset("tblMailItems")
rstMerge.AddNew
rstMerge!Surname = Forms!frmapplypost.Surname
rstMerge!Title = Forms!frmapplypost.Title
rstMerge!Initials = Forms!frmapplypost.Initials
rstMerge!Address1 = Forms!frmapplypost.Address1
rstMerge!Address2 = Forms!frmapplypost.Address2
rstMerge!Address3 = Forms!frmapplypost.Address3
rstMerge!Address4 = Forms!frmapplypost.Address4
rstMerge!Address5 = Forms!frmapplypost.Address5
rstMerge!Address6 = Forms!frmapplypost.Address6
If Not Forms!frmapplypost.PostCode = "Unknown" Then
rstMerge!PostCode = Forms!frmapplypost.PostCode
End If
rstMerge!ApplicantID = Forms!frmapplypost.ApplicantID
rstMerge!PostNumber = Forms!frmapplypost!sbfPostApp.Form!PostNumber
rstMerge!PostTitle = Forms!frmapplypost!sbfPostApp.Form!PostTitle
rstMerge!DateAppReturned = Forms!frmapplypost!sbfPostApp.Form!DateAppReturned
rstMerge!ClosingDate = Forms!frmapplypost!sbfPostApp.Form!ClosingDate
rstMerge!DisclosureText = Forms!frmapplypost!sbfPostApp.Form!DisclosureLevel.Column(2)
rstMerge!Selected = True
rstMerge.UPDATE
rstMerge.Close
'if local report then run else mail merge to word
If Not Me.cbodocument.Column(3) = "" Then
Select Case Left(Me.cbodocument.Column(3), 3)
Case "rpt"
printreport Me.cbodocument.Column(3)
Case "qry"
If Nz(DCount("*", Me.cbodocument.Column(3))) = 0 Then
glrstatus
MsgBox "Nothing to print or details incomplete"
Exit Sub
End If
'export table to rtf format with random file name
ExportMergeData Me.cbodocument.Column(3), rstsys!documentpath, LetterTemplate & ".dot", rstsys!templatepath, 0, UsePrinter, 0, LetterTemplate & Format(Date, "yyyymmdd") & ".doc"
rstsys.Close
Case Else
End Select
Else
'export table to rtf format with random file name
Dim intPrint As Integer
If IsNull(UsePrinter) Or UsePrinter = "" Then
intPrint = 1
Else
intPrint = 2
End If
If Nz(DCount("*", "tblMailItems")) = 0 Then
glrstatus
MsgBox "Nothing to print or details incomplete"
Exit Sub
End If
ExportMergeData "tblMailItems", rstsys!documentpath, LetterTemplate & ".dot", rstsys!templatepath, intPrint, UsePrinter, 0, LetterTemplate & Format(Date, "yyyymmdd") & ".doc"
End If
glrstatus
End Sub