UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

2 Pages V   1 2 >  
Reply to this topicStart new topic
> Creating report from filtered records.    
 
   
ckbanks
post Jul 8 2004, 12:05 PM
Post #1

UtterAccess Enthusiast
Posts: 79



I am able to filter records based on certain criteria. How do I then create a report only on that data? When I try to create a report I get all records no matter what the filtered results were. Any help?
Go to the top of the page
 
+
SerranoG
post Jul 8 2004, 12:16 PM
Post #2

UtterAccess VIP
Posts: 2,121
From: Lansing, MI USA



I assume you open the report from a button on a form. On the button's ON CLICK event, you code this:

CODE
DoCmd.OpenReport "Your Report Name Here", acViewPreview, , "[My Field] = '" & Me.txtMyField & "'"

if text or

CODE
DoCmd.OpenReport "Your Report Name Here", acViewPreview, , "[My Field] = " & Me.txtMyField

if a number or

CODE
DoCmd.OpenReport "Your Report Name Here", acViewPreview, , "[My Field] = #" & Me.txtMyField & "#"

If a date...
Go to the top of the page
 
+
ckbanks
post Jul 8 2004, 12:30 PM
Post #3

UtterAccess Enthusiast
Posts: 79



What goes in "Me.txtMyField"? The field I'm sorting by is a date and it's name is "IssueDate1".
Go to the top of the page
 
+
ckbanks
post Jul 8 2004, 12:40 PM
Post #4

UtterAccess Enthusiast
Posts: 79



The field I'm sorting by is a date. What goes where you have a "#" symbol? Also, what do I put where it says "Me.txtMyField"? Thanks for your help!!
Go to the top of the page
 
+
SerranoG
post Jul 8 2004, 12:43 PM
Post #5

UtterAccess VIP
Posts: 2,121
From: Lansing, MI USA



Use the date example like this:

CODE
DoCmd.OpenReport "Your Report Name Here", acViewPreview, , "[IssueDate1] = #" & Me.IssueDate1 & "#"


Assuming the name of the field in the table is IssueDate1 and the name of the textbox is also IssueDate1. For example, if your table is tblMyTable and the date field in the table is dtmIssueDate1 and the textbox on the form is called txtIssueDate1, then

CODE
DoCmd.OpenReport "tblMyTable", acViewPreview, , "[dtmIssueDate1] = #" & Me.txtIssueDate1 & "#"
Go to the top of the page
 
+
SerranoG
post Jul 8 2004, 12:45 PM
Post #6

UtterAccess VIP
Posts: 2,121
From: Lansing, MI USA



The # symbol is not a value, it is called a delimiter. You use it to surround dates when writing SQL statements with WHERE clauses.

For example: "SELECT [dtmIssueDate1] FROM tblMyTable WHERE [dtmIssueDate1] = #" & Date() & "#"
Go to the top of the page
 
+
ckbanks
post Jul 8 2004, 12:53 PM
Post #7

UtterAccess Enthusiast
Posts: 79



I got an error. It says, "Compile Error: Method or data member not found". The highlighted text is ".txtIssueDate1". "Issue Date1" is the name of the text box. Thanks for your patience.
Go to the top of the page
 
+
ckbanks
post Jul 8 2004, 01:00 PM
Post #8

UtterAccess Enthusiast
Posts: 79



I tried it this way too.

DoCmd.OpenReport "Fund Development Log", acViewPreview, , "[IssueDate1] = #" & Me.IssueDate1 & "#"

With this I got the error, "Syntax error in date in query expression '([Issue Date1] = ##)"

Clint
Go to the top of the page
 
+
SerranoG
post Jul 8 2004, 01:06 PM
Post #9

UtterAccess VIP
Posts: 2,121
From: Lansing, MI USA



QUOTE
DoCmd.OpenReport "Fund Development Log", acViewPreview, , "[IssueDate1] = #" & Me.IssueDate1 & "#"

With this I got the error, "Syntax error in date in query expression '([Issue Date1] = ##)"

This error occured probably because the textbox you specified, Me.IssueDate1, is empty. Make sure the name of the textbox is really IssueDate1. Click on it once and view its name in the property window. Or if the name of the textbox is correct, but the date really IS blank, then try this:

CODE
If IsNull(Me.IssueDate1) Then
   'List all records in the report.
   DoCmd.OpenReport "Fund Development Log", acViewPreview
Else
   'List just the ones for Issue Date 1.
   DoCmd.OpenReport "Fund Development Log", acViewPreview, , "[IssueDate1] = #" & Me.IssueDate1 & "#"
End If
Go to the top of the page
 
+
johnmcmahon
post Jul 8 2004, 01:47 PM
Post #10

UtterAccess Member
Posts: 48



Brilliant!

I had the same question! Thanks, Greg.
Go to the top of the page
 
+
ckbanks
post Jul 9 2004, 08:02 AM
Post #11

UtterAccess Enthusiast
Posts: 79



Sweet!! Thanks Greg! It works great.
Clint
Go to the top of the page
 
+
ckbanks
post Aug 16 2004, 11:05 AM
Post #12

UtterAccess Enthusiast
Posts: 79



Greg,

I'm finally not getting any errors anymore. Thanks! The problem I have now is that the report only creates a report based on the "active" date in the "IssueDate1" field. For example in the 8 filtered our records the report includes whatever current date is showing in the record I'm viewing on my computer screen. It filters all the records correctly, but the report doesn't include all the filtered results, only the date that I can see. I can change records and then create another report that has that date in it, but it won't include all the dates in the filtered results. What should I do about this? Thanks for your help so far.

Clint
Go to the top of the page
 
+
SerranoG
post Aug 16 2004, 11:57 AM
Post #13

UtterAccess VIP
Posts: 2,121
From: Lansing, MI USA



You lost me there... please restate your problem more clearly. Thanks.
Go to the top of the page
 
+
ckbanks
post Sep 28 2004, 11:06 AM
Post #14

UtterAccess Enthusiast
Posts: 79



I have successfully been able to filter out records based on a certain date range thanks to your help. Now what I want to do is create a report based on the filtered data. I tried this already and failed. For example our of 156 records I filtered out 4 because they met the criteria. The active window says at the bottom, "1 of 4 (filtered". When I click on the report button and go to the report that shows this data only the filtered date that I'm actively looking at shows up in the report. In this example records 1-2 have the same date. They all show up in the report. Records 3-4 don't. If I go to record three and click on the report button, only records 3 and 4 show up because they have the same date. How do I get all the filtered records that met the date criteria to show up in the report?
Go to the top of the page
 
+
SerranoG
post Sep 28 2004, 12:12 PM
Post #15

UtterAccess VIP
Posts: 2,121
From: Lansing, MI USA



Oh, you confused me because you're talking about filtering in two places... your form and your report. You filtered your FORM down to four records. Now when you open your REPORT, it's filtering on that date and only showing two out of four records. Essentially what you're doing is filtering twice.

I think what your original question should have been this. If you filter a FORM and open the REPORT, how do you reflect the same filter on the report? It sounded like in your original question that you did NOT filter the form and that you filtered the report based on a date on the form.

What you do is filter the form as you've been doing. Issue a DoCmd.OpenReport command on the button but do NOT specify a WHERE clause. This will open the report with everything in it.

On the report's ON OPEN event, you put this:

CODE
Me.FilterOn = True
Me.Filter = Forms.frmMyFormName.Form.Filter


Change frmMyFormName to your actual form name. When the report opens (with everything), it'll immediately take on the same filter as the active form. In your case, you'll see the same four records (assuming the form and the report have the same underlying table or query).
Go to the top of the page
 
+
ckbanks
post Sep 28 2004, 01:55 PM
Post #16

UtterAccess Enthusiast
Posts: 79



I couldn't get this to work yet. The form I'm generating the report off of is a subform. Does that change things any? I keep getting the debugger for the second line of the code you offered even though I have changed it like you suggested.
Go to the top of the page
 
+
SerranoG
post Sep 28 2004, 01:59 PM
Post #17

UtterAccess VIP
Posts: 2,121
From: Lansing, MI USA



If the report is getting the filter from a subform, then you'd do this:

CODE
Me.Filter = Forms.frmMyMainFormName.Form.sfrMySubFormName.Filter


Change frmMyMainFormName and sfrMySubFormName to the actual names.
Go to the top of the page
 
+
ckbanks
post Sep 28 2004, 02:14 PM
Post #18

UtterAccess Enthusiast
Posts: 79



It keeps giving me the error "expected end of statement" after I type in my form names. Is there another problem?
Go to the top of the page
 
+
SerranoG
post Sep 28 2004, 02:26 PM
Post #19

UtterAccess VIP
Posts: 2,121
From: Lansing, MI USA



If your form names have spaces in them (a no-no), then you must surround the names with brackets.

CODE
Me.Filter = Forms.[frmMyMainFormName].Form.[sfrMySubFormName].Filter
Go to the top of the page
 
+
ckbanks
post Sep 28 2004, 02:28 PM
Post #20

UtterAccess Enthusiast
Posts: 79



Now I'm getting the error "Object doesn't support this property or method". Sorry for all the problems.
Go to the top of the page
 
+

2 Pages V   1 2 >
Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th May 2013 - 10:15 PM