468,296 Members | 1,262 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,296 developers. It's quick & easy.

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
Nov 14 '11 #1
2 5696
sierra7
446 Expert 256MB
Michael
First when you refer to a 'radio' button I hope you mean 'Command' button!

The code behind the button is probably something like :-
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdReport_Click()
  2. On Error GoTo Err_cmdReport_Click
  3.  
  4.     Dim stDocName As String
  5.  
  6.     stDocName = "MyReportName"
  7.     DoCmd.OpenReport stDocName, acViewReport
  8.  
To print just the current record you need to add a filter criteria, something like;

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdReport_Click()
  2. On Error GoTo Err_cmdReport_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stCriteria as String
  6.  
  7.     stDocName = "MyReportName"
  8.     stCriteria = "[MyID] =" & Me!MyID  ' where MyID is numeric
  9.  
  10.     DoCmd.OpenReport stDocName, acViewReport, , stCriteria
  11.  
If the criteria was a Text field or a Date the syntax would change as below
Expand|Select|Wrap|Line Numbers
  1. stCriteria = "[MyText] = '" & Me!MyText & "'" 
  2. 'or
  3. stCriteria = "[MyDate] = #" & Me!MyDate  & "#"
Notice the extra comma after acViewReport (or acViewPreview if you are previewing before printing)
Hope this helps
S7
Nov 14 '11 #2
NeoPa
32,071 Expert Mod 16PB
@S7
Expand|Select|Wrap|Line Numbers
  1. stCriteria = "[MyDate] = #" & Me!MyDate & "#"
That is a commonly held misconception (in America). It should be :
Expand|Select|Wrap|Line Numbers
  1. 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.
Nov 14 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Tim Graichen | last post: by
4 posts views Thread by William Bradley | last post: by
2 posts views Thread by Paul Mendez | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.