I now you have been ask't this a thousand times. But please take in to
account I am a complete novice and a bit stupid. I have a simple database
using Access 97. I have 1 form 1 report. I just want to know how I can put a
command button on the form that will print one report instead off all the
reports. It has to be simple I don't understand code or macro.
Thanks to anybody who can help in advance
If you want to print the report displaying only the item that's
currently displayed on the form, there are several ways to do so.
Perhaps the simplest would be to use the Toolbox Wizard to create a
command button on the form - one of the options is "print a report".
You will then need to make one simple edit to the VBA code generated
by the wizard. It will look something like
Private Sub cmdPrintReport_Click()
On Error GoTo Err_cmdPrintReport_Click
Dim stDocName As String
stDocName = "rptMyReport"
DoCmd.OpenReport stDocName, acNormal
Exit_cmdPrintReport_Click:
Exit Sub
Err_cmdPrintReport_Click:
MsgBox Err.Description
Resume Exit_cmdPrintReport_Click
End Sub
Edit this by adding just a couple of lines:
Private Sub cmdPrintReport_Click()
On Error GoTo Err_cmdPrintReport_Click
Dim stDocName As String
Dim stCriteria As String ' define a new string variable
stDocName = "rptMyReport"
' put a criterion in the variable
stCriteria = "[UniqueIDField] = " & Me!txtUniqueIDField
' and reference the criteria in the OpenReport call
DoCmd.OpenReport stDocName, acNormal, WhereCondition := stCriteria
Exit_cmdPrintReport_Click:
Exit Sub
Err_cmdPrintReport_Click:
MsgBox Err.Description
Resume Exit_cmdPrintReport_Click
End Sub
Since I don't know your table or fieldnames you'll need to edit
UniqueIDField to whatever field in your table uniquely identifies the
item to be printed; txtUniqueIDField should be changed to the name of
a form control which contains that field.