"which uses the ID of the current record in its WHERE clause" can you explain this sentence? I am not understanding it.
Apologies if I was obscure - NeoPa's post is what I meant. You just write the query with the fields you want in the letter, then the report with the boilerplate text and the fields (such as client name & address)from the query. Then on the form where the users sees the individual record you put a button with code LIKE this behind its OnClick event:
- Private Sub buttonPrintIndividual_Click()
-
On Error GoTo Err_buttonPrintIndividual_Click
-
Dim strReportName As String
-
Dim whereClause As String
-
strReportName = "rptStandardIndividualLetter"
-
'Get the ID of the current record from the form
-
whereClause = me.RecordID.value
-
'Check that there is a current record
-
If whereClause <> "" Then
-
DoCmd.OpenReport strReportName, acViewPreview, , whereClause
-
Else
-
MsgBox "There is no current record"
-
Docmd.cancelevent
-
End if
-
Exit_buttonPrintIndividual_Click:
-
Exit Sub
-
Err_buttonPrintIndividual_Click:
-
MsgBox Err.Description
-
Resume Exit_buttonPrintIndividual_Click
-
End Sub
I say LIKE this because I have not tested this code although I have used similar. In effect the query and report you write will return all of the records, but when you pass the WhereClause on the OpenReport event it filters the recordset for the report down to just that record that matches the ID of the record that is current in the form. I hope that is clearer?
One other point - I have found that you cannot guarantee that when an Access Report is exported to Word that the formatting in Word exactly matches what you would see if you printed the report directly from Access. In my experience it is a waste of time to put any effort into layout, graphics or lines in a report as they get lost or wrecked in the export to Word. Simpler is better. Of course you could just print the letter from Access assuming you are sending snail-mail.