1) put a button on your form. Follow the wizard to Preview your report.
2) In the design mode of the form, view the Properties window, and click the button. In the OnClick event of the button, click the build button (the little button to the right of the event with the three dots on it). It will open up to the code the wizard wrote for you. It will look something like this:
Code:
Private Sub Command6_Click()
On Error GoTo Err_Command6_Click
Dim stDocName As String
stDocName = "ActualsByBoard"
DoCmd.OpenReport stDocName, acPreview
Exit_Command6_Click:
Exit Sub
Err_Command6_Click:
MsgBox Err.Description
Resume Exit_Command6_Click
End Sub
This will open your report.
3) Since you want to only see the current record, you'll need to add to the code above. You'll be adding what is called a "where" string to tell it to open the report to only one record. Assuming the ID field on your form is called "ID", and the ID field in the table or query that your report is based on is called "ReportID", the code will look like this:
Code:
DoCmd.OpenReport stDocName, acPreview,,"[ReportID] = " & me.ID
So that's how you tell it to open the report for only certain criteria.
(if you didn't know, the keyword "me" refers to the form or report object you're sitting on at the moment).
If you simply type a comma after the line of code that the wizard wrote for you (DoCmd.OpenReport stDocName, acPreview) you will see it prompting you for more info. type a second comma, and it will want the WHERE string, which is what i wrote above. If some place you type the word me. (me and dot/period) you will see it pop up with a list of things you can choose, some of which are the fields you have in the form.
Hope this helps.
g
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244