Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2014
    Posts
    12

    Pulling only one record into a report

    All,



    I have done this before, but just cannot remember how I did it ...so I hope someone with way more knowledge knows this off the top of his/her smart head!

    I have a form and a subform created. From these two, I have created a report that populates with the information. However, I cannot remember the code, nor where to put it in order for the report to only pull whatever record is current in the form. Currently, the report will create a page for each record stored in the table.

    I hope this makes sense and any help would be greatly, greatly, greatly appreciated (and I promise to write it down this time)!

    Thanks so much!!!!

    (Access 2007)

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    docmd.openreport "rptMyrpt" ,acViewPreview,,"[recID]=" & IDnum

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You can apply the filter to the report when you open it.

    Something like this

    Code:
    Dim strReport as string
    dim strWhere as string
    strReport = "MyReportName"
    strWhere = "[FieldPK] = " & Me!FieldPK
    DoCmd.OpenReport "strReport", acViewPreview, , strWhere

  4. #4
    Join Date
    Jul 2014
    Posts
    12
    Do I put this in the code on the form or the report? I am thinking the form, but just wanted to double check....thanks so much!!!

  5. #5
    Join Date
    Jul 2014
    Posts
    12
    Quote Originally Posted by ItsMe View Post
    You can apply the filter to the report when you open it.

    Something like this

    Code:
    Dim strReport as string
    dim strWhere as string
    strReport = "MyReportName"
    strWhere = "[FieldPK] = " & Me!FieldPK
    DoCmd.OpenReport "strReport", acViewPreview, , strWhere


    Where would I put this? And thank you!!!

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You could add a Command Button to your form and create a click event. Use the Command Button's property sheet. Under the Event tab, click the ellipses(...) next the field named "On Click". Select the option, Code Builder.

    You will need to adjust the Report name and field names to match your application's needs.

    Code:
    strReport = "MyReportName"
    strWhere = "[FieldPK] = " & Me!FieldPK

  7. #7
    Join Date
    Jul 2014
    Posts
    12
    Quote Originally Posted by ItsMe View Post
    You could add a Command Button to your form and create a click event. Use the Command Button's property sheet. Under the Event tab, click the ellipses(...) next the field named "On Click". Select the option, Code Builder.

    You will need to adjust the Report name and field names to match your application's needs.

    Code:
    strReport = "MyReportName"
    strWhere = "[FieldPK] = " & Me!FieldPK


    I'm sorry. One last question. I understand changing the report name, but when you say adjust the field name, I am not sure which field to put. Would it be the one that links the main form and subform together?

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    It may be. There should be something, some value, that will determine how you filter the report. This is typically a field that is a Key value. Typically it would be the Primary Key or Foreign Key field.

    This concept is similar to the concept of linking Main and Child links for subforms.

  9. #9
    Join Date
    Jul 2014
    Posts
    12
    Thank you so very much for your help!!! I really appreciate it!

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Not a problem and welcome to the forum. We are all happy to help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-03-2012, 01:22 PM
  2. Query having trouble pulling last record
    By robsworld78 in forum Queries
    Replies: 25
    Last Post: 12-18-2011, 08:32 PM
  3. Replies: 1
    Last Post: 12-05-2011, 03:26 PM
  4. Pulling up record ID instead of combo box value
    By edzigns in forum Programming
    Replies: 1
    Last Post: 04-29-2011, 08:03 AM
  5. Pulling Record Info From Sub Form
    By redlich23 in forum Forms
    Replies: 1
    Last Post: 09-02-2009, 02:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums