How to create report showing just the current record in form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • michael george
    New Member
    • Nov 2011
    • 1

    How to create report showing just the current record in form

    Hi,

    I am a recreational user of access and I enjoy making small databases. My question is when I add records to a form i want to create a report on the form currently displayed on screen, at the moment when i created a report radio button the resulting report displays all records in database. how can i create report showing just the current record in form?
    Your help would be immensely appreciated.

    Thanks

    Mike
  • sierra7
    Recognized Expert Contributor
    • Sep 2007
    • 446

    #2
    Michael
    First when you refer to a 'radio' button I hope you mean 'Command' button!

    The code behind the button is probably something like :-
    Code:
    Private Sub cmdReport_Click()
    On Error GoTo Err_cmdReport_Click
    
        Dim stDocName As String
    
        stDocName = "MyReportName"
        DoCmd.OpenReport stDocName, acViewReport
    To print just the current record you need to add a filter criteria, something like;

    Code:
    Private Sub cmdReport_Click()
    On Error GoTo Err_cmdReport_Click
    
        Dim stDocName As String
        Dim stCriteria as String
    
        stDocName = "MyReportName"
        stCriteria = "[MyID] =" & Me!MyID  ' where MyID is numeric
    
        DoCmd.OpenReport stDocName, acViewReport, , stCriteria
    If the criteria was a Text field or a Date the syntax would change as below
    Code:
    stCriteria = "[MyText] = '" & Me!MyText & "'" 
    'or
    stCriteria = "[MyDate] = #" & Me!MyDate  & "#"
    Notice the extra comma after acViewReport (or acViewPreview if you are previewing before printing)
    Hope this helps
    S7

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32634

      #3
      @S7
      Code:
      stCriteria = "[MyDate] = #" & Me!MyDate & "#"
      That is a commonly held misconception (in America). It should be :
      Code:
      stCriteria = "[MyDate] = #" & Format(Me.MyDate, "m/d/yyyy\#")
      This is explained in detail in Literal DateTimes and Their Delimiters (#).

      @Michael
      It is not correct to think that you are adding records to a form. You are actually adding them to the table behind the form (that it's bound to). As such, your question as it stands has no direct answer. If you were to indicate that these (newly added) records had any identifying characteristics (Such as an entry date for instance), then they could be used to filter the records (as S7 has already very well indicated) for the report. Without any such information though, what you request is not possible.

      Comment

      Working...