to print report based on primary key

deema

Registered User.
Local time
Today, 10:49
Joined
Jul 31, 2012
Messages
14
Hello everyone

I have created a report but I want it to be filtered based on the primary key.
So I can print single page with data that belongs to single primary key.



Thank you and appreciate your help.
 
Thank you very much but is there another way. I couldn't get it
 
Sure, you can base the report on a parameter query, though that is more limiting. You can set the filter in the open event of the report. If you post what you tried and what "couldn't get it" means exactly, perhaps we can figure out the problem.
 
Now I am opening the report

- design view
- Botton
- (right click) properties
- name : I write the name of the report
- caption: I write the name of the command
- from event- on click: [Event Procedure] then I press the botton next to it
past this

Dim strDocName As String
Dim strWhere As String
strDocName = "rptSomeReport"
strWhere = "[RunID]=" & me!RunID
DoCmd.OpenReport strDocName, acPreview, , strWhere




Is my process right? andi what should I put in [RunID]
 
That looks okay. Do you get an error, or ? What is the data type of RunID in the table?
 
ya there is an error 2465 (cant find the field RunID)
RunID is a number
 
Well, in this line:

strWhere = "[RunID]=" & me!RunID

the first reference to it needs to be a field in the report's record source. The second reference to it needs to be the control on the form you're running the report from that contains that value. It sounds like one of those is off.
 
it means the first one: the name of the field which is (ID)
the second one the name of the report which is (Class_A)



Private Sub to_print_Click()
Dim strDocName As String
Dim strWhere As String
strDocName = "rptSomeReport"
strWhere = "[ID]=" & Me!Class_A
DoCmd.OpenReport strDocName, acPreview, , strWhere
End Sub


but it still gives me an error

I attached a sample of my file and screenshots
 

Attachments

  • sc1.jpg
    sc1.jpg
    86 KB · Views: 126
  • sc2.jpg
    sc2.jpg
    83.4 KB · Views: 105
  • Database1.accdb
    Database1.accdb
    1.1 MB · Views: 106
The code is intended to be in a form that would be opening the report. I don't think it will work from within the report, since it's already open at that point. You can probably either set the filter or reset the record source of the report in report view and then print it, though I've never tried.
 
Oh, and the reason nothing is happening is because the code is associated with a non-existent button named "to_print". The error you get is because the field on the form is "ID", not "RunID" (as is the field in the table).
 
thank you very much

I will try another code as in attachment

but what should I put in wherecondition and openargs
 

Attachments

  • sc3.jpg
    sc3.jpg
    86.1 KB · Views: 126
Check out the form in your db, and double click on any of the ID's.
 

Attachments

just amazing!!! Thank you very very much

I want to know HOW. did you use a code?!
and is it possible to enter the ID number manually instead of double click coz I have a database with over 50,000 records
 
Yes, look at the code behind the double click event of that textbox. It's the same as you were trying to use in the report. If you wanted you could have a text box or combo box where the user entered/selected an ID number, and put the same code behind a button, adjusting to point to that text/combo box.
 
it works (:

THANK YOU VERY MUCH

Appreciate all your help REALLY!!
 

Users who are viewing this thread

Back
Top Bottom