Limiting a report to shown a single record from form

David1234

Registered User.
Local time
Today, 23:20
Joined
Nov 16, 2011
Messages
22
Hi,

I have a form/subform combination on my database.

One record on the subform can relate to several records on the subform, i.e

Record 1, has five incidents on it so records in the subform are 1.1, 1.2, 1.3 etc.

I then need a print off of these in report format, I only need a single record for the report though. The issue i'm having is that all of the records are printing on the report! Is there any criteria I can state to print the current form? I know I can create a form button to print current form, but I need the report format.

Any advice!!?
 
You will need to create a report that looks like your form in order to do that. You can save a copy of your form as a report and use the code you know to print the current record.
 
I do this with my reports and forms (if I understood your message)... you need to play with your code a little so that the code for your report button looks a little like this:

Private Sub YOURBUTTON_Click()
On Error GoTo Err_YOURBUTTON_Click


Dim stDocName As String
stDocName = "REPORT_NAME"
stLinkCriteria = "[LINKED_FIELD]=" & Me![LINKED_FIELD]
DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

Exit_YOURBUTTON:
Exit Sub

Err_YOURBUTTON_Click:
MsgBox Err.Description
Resume Exit_YOURBUTTON

End Sub


The bold text shows the bits for you to change. I imagine that this code is quite clumsy and someone with knowledge of VBA can tidy it up - this was my Heath-Robinson approach, combining the code from buttons that perform different functions, but it seems to work.

If you don't already know how, then access the the code for your buttons by hitting Alt and F11 then click through the options to find your form, then scroll through the code until you find a section titled with your button's name, then perform surgery on it as described above!

Good luck!
 
So basically, the sytax of the OpenForm is essentially the same as OpenReport. Since you already had the OpenForm command with the WHERE clause, all you had to do was to replace OpenForm for OpenReport.
 

Users who are viewing this thread

Back
Top Bottom