By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,072 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,072 IT Pros & Developers. It's quick & easy.

How to create report showing just the current record in form

P: 1
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
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 446
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
Expert Mod 15k+
P: 31,709
@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.