473,480 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Report Filtering Issue

20 New Member
Hello,

I have a report that is supposed to show the teachers that have taught specific classes this year. I'm almost done, I just need the report to filter the data before opening.

In setting the button that opens the report to filter the data I'm being asked for input for my Fall, Spring, and Summer... which shouldn't happen. If I add a single quote to those terms, I no longer am prompted for input, but am told that my expression is too complex.

I'm not seeing what I'm doing wrong with my code. Any help is appreciated.

Expand|Select|Wrap|Line Numbers
  1.  
  2. pyer = ([Forms]![MENMain3]![NavigationSubform].[Form]![SYr]) - 1
  3.     yer = [Forms]![MENMain3]![NavigationSubform].[Form]![SYr]
  4.     nyer = ([Forms]![MENMain3]![NavigationSubform].[Form]![SYr]) + 1
  5.  
  6.  
  7.     DoCmd.OpenReport "QuickScheduleCourse", acPreview, , "[SemesterYear]=" & ((pyer & " Or " & yer & " Or " & nyer) & " AND " & "[Semester]=" & "Fall") & " or " & "[SemesterYear]=" & ((pyer & " Or " & yer & " Or " & nyer) & " AND " & "[Semester]=" & "Spring") & " or " & "[SemesterYear]=" & ((pyer & " Or " & yer & " Or " & nyer) & " AND " & "[Semester]=" & "Summer")
  8.  
  9.  
Mar 29 '16 #1
2 1070
PhilOfWalton
1,430 Recognized Expert Top Contributor
I think ...note the word think that you are missing quotes round the seasons.

Substitute "[Semester]=" & "Fall") with
"Semester = " & Chr$(34) & "Fall" & Chr$(34)
Do something similar for the other seasons

Incidentally, you don't need the square brackets.
Phil
Mar 30 '16 #2
mbizup
80 New Member
The above comment is correct... you need to delimit any text data with quotes.

Additionally, your VBA is gong to result in SQL criteria including conditions along the lines of:

Expand|Select|Wrap|Line Numbers
  1. SemesterYear = (Thie OR That OR SomethingElse)

This syntax will fail in SQL. You have two options for a list of ORs:

1. Spell it out as separate comparisons like this. Also note the parentheses to separate a list of ORs from ands. The hierarchy of operations evaluates ANDs before ORs (similar to multiplication and addition, respectively), so you need to use parentheses to ensure that the ORs are grouped together.

Expand|Select|Wrap|Line Numbers
  1. (SemesterYear = This OR SemesterYear = That OR SemesterYear = SomethingElse) AND Semester='Fall'

2. The other option is to use the IN keyword with a comma delimited list. Pro: the syntax is simpler. Con: You might see a noticeable performance hit.

Expand|Select|Wrap|Line Numbers
  1. SemesterYear IN (This, That, SomethingElse) AND Semester= 'Fall'

Additional tips:
1. Work out your query syntax, including criteria in the query editor first, and then put it into VBA.

2. Use a SQL string to build your criteria, and use that string in your report open statement. That makes for cleaner code, and more importantly allows you to view and test your criteria (very helpful when debugging):

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL as string
  2. strSQL = "[SemesterYear]=" ' etcetera
  3. DoCmd.OpenReport "QuickScheduleCourse", acViewPreview, strSQL
  4. " the following line will print your criteria into the editor's immediate window, allowing you to copy/paste/test/debug it in the query editor
  5. Debug.Print strSQL 
Mar 30 '16 #3

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

Similar topics

2
6544
by: Ashish Shridharan | last post by:
Hi All, I'm not very sure if this is the forum for my question but i was hoping someone could direct me to the right place (or answer my question). I am using the .NET crystal report viewer...
1
2637
by: diskoduro | last post by:
Hi! I'm trying to get help to an unexpected problem that has appeared while I was writing a new application. I want to opeon a report of product sales by filtering previously from a listbox in a...
2
2545
by: John Baker | last post by:
Hi: I am developing a report, and have run into a reference snag. I have subtotals which i generate on the report, and have named "tasksum", which represent the number of hours an individual...
3
2711
by: ahaque38 | last post by:
Hello. Using A2K SP3, I am having the following problem with a report using "Sorting and Grouping". I have recently added a grouping in the reports for "Category2<>'CONTRACTS'". I have...
0
1215
by: AA Arens | last post by:
I have a create report function showing reports for every record that is listed in the tblCalls table. In my situation one report per call that comes from a company. I would like to have a...
3
4857
by: fperri | last post by:
Hi, I have a report that I am designing in Visual Web Developer, I have two Matrix tables on my report - in the same list - and I have positioned them in the design window so that they are right...
0
1445
by: Phillip | last post by:
Hi all, When I tried to deploy a report that I created, I received following error message from SQL server 2005. "Client found response content type of 'text/html; charset=utf-8, but...
1
2329
by: bh | last post by:
I have a vb.net 2003 front-end, which is a crystal report (8.5) viewer/generator. When trying to export the crystal report to excel spreadsheets, today, which has always been successful, up until...
3
1761
by: Joseph Geretz | last post by:
I'm using the Request Filter documentation which can be found here: http://msdn.microsoft.com/en-us/library/system.web.httprequest.filter.aspx In this example, two filters are installed, one...
0
1465
by: Justin K | last post by:
I have an issue with a Crystal Report that I am using in my C# program. I created the report in Crystal Reports XI(R2). The report's datasource is an SQL stored procedure, and contains a...
0
7037
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7076
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6732
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4472
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.