473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can I code ALL Teams on my report when querying all records.

I have a report in Access 2010 based on SQL parameters.

The user inputs either a team number or * for all teams. The query will return the results for the selected team or all the teams based on user input.

What I need is the team to be displayed on the report.

I am using expression builder. I can get this to work for a single team, but not when the user inputs "*". It just displays 89, or the highest team in the query result.

This is what I have in expression builder:
Expand|Select|Wrap|Line Numbers
  1. =IIf(IsNumeric([Query1.Team]),[Query1.Team],"ALL")
I have tried using the name of the controls in place of Query1, I don't think this should be this hard.

The original report was created in 1995 in Access. I'm just trying to recreate this as a novice from a .mde version.
Nov 10 '15 #1
2 827
NeoPa
32,556 Expert Mod 16PB
You're nearly there. You want :
Expand|Select|Wrap|Line Numbers
  1. =IIf(IsNumeric([Team]),[Team],'ALL')
The brackets ([ & ]) should surround each element of the reference. In this case the only element you need is Team. If you needed Query1.Team then it would be [Query1].[Team].
Nov 12 '15 #2
strive4peace
39 Expert 32bit
Better to test the criteria controls and only apply criteria if they are filled. Then you can specify the WHERE clause of OpenReport to limit it for the records that are specified.

here is an example that tests criteria and builds a criteria string to use as a parameter in OpenReport for the WHERECONDITION clause

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport reportname[, View][, FilterName][, WhereCondition]
ie:
Expand|Select|Wrap|Line Numbers
  1.     DoCmd.OpenReport "MyReport", acViewPreview,, varCriteria
WHERE
varCriteria is how to limit the records. For instance -->
"CustomerID = " & Me.CustomerID
OR
"PartID = " & me.PartID & " AND OrderDate =#" & me.OrderDate & "#"
OR
"Not IsNull( [fieldname] )"

varCriteria is the WHERE clause of an SQL statement without the word "where"

an advantage of testing controls as you construct the SQL is that you can ignore criteria that the user didn't fill out values to compare to

~~~
assuming you have are in the code behind your ReportMenu form... here is a general case:

'~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand|Select|Wrap|Line Numbers
  1.    'tell Access you are going to create a variable
  2.    dim varFilter as variant
  3.  
  4.    'initialize the variable
  5.    varFilter = null
  6.  
  7.    'substitute YOUR controlname in here after "Me."
  8.    'we are testing to see if it is filled out
  9.    'if it is, we are going to make varFilter hold the criteria
  10.    If not IsNull(me.text_controlname ) Then
  11.       varFilter = "[TextFieldname]= '" & me.controlname_for_text  & "'"
  12.    end if
  13.  
  14.    'test the next control
  15.    If not IsNull(me.date_controlname ) Then
  16.       'if we alread have criteria, add AND to specify that and more
  17.       varFilter = (varFilter + " AND ") _
  18.         & "[DateFieldname]= #" & me.controlname_for_date  & "#"
  19.    end if
  20.  
  21.    'test the next control
  22.    If not IsNull(me.numeric_controlname ) Then
  23.       varFilter = (varFilter + " AND ") _
  24.         & "[NumericFieldname]= " & me.controlname_for_number
  25.    end if
  26.  
  27.    if not IsNull(varFilter) then  
  28.        DoCmd.OpenReport "ReportName", acViewPreview, , varFilter
  29.    else
  30.        DoCmd.OpenReport "ReportName", acViewPreview
  31.    end if
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'SPACE UNDERSCORE at the end of a line means that the statement is continued on the next line
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have used:

TextFieldname to show how text needs to be delimited with ' or " (single or double quote marks ... double can be used anywhere; single has limitations in Access)

DateFieldname to show that dates need to be delimited with #

NumericFieldname to show that numbers are not delimited

each time, we are testing to see if a control for criteria is filled out.

If it is, we are going to see if we first need to add AND (if the filter string already says something)
Then we are going to add the criteria for that filter
varFilter = (varFilter + " AND ") & ... ' some other criteria

make sure that the referenced fields are in the underlying RecordSet for the report -- and it is best for referenced fields to be in controls on the report (the Visible property can be No)

For a Date Range, you would do:

Expand|Select|Wrap|Line Numbers
  1.    If not IsNull(me.date1_controlname ) Then
  2.       varFilter = (varFilter + " AND ") _
  3.         & "[DateFieldname]>= #" & me.date1_controlname & "#"
  4.    end if
  5.  
  6.    If not IsNull(me.date2_controlname ) Then
  7.       varFilter = (varFilter + " AND ") _
  8.         & "[DateFieldname] <= #" & me.date2_controlname & "#"
  9.    end if
  10.  
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you are not using the American Date Format, then you may wish to use the ISO 8601 representation of the date:
Expand|Select|Wrap|Line Numbers
  1. Format(me.date_controlname, "\#yyyy\-mm\-dd\#")
  2.  
  3. instead of
  4. "#" & me.date_controlname & "#"
  5.  
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

IF you want to also PRINT the criteria on the report

put a LABEL on your PageFooter
name --> Label_Criteria

then, in the OnFormat event of the ReportHeader

'~~~~~~~~~~~~~~~~~~
Expand|Select|Wrap|Line Numbers
  1.    if len(trim(nz(Me.Filter,""))) > 0 then
  2.       me.Label_Criteria.Caption = Me.Filter
  3.       me.Label_Criteria.Visible = true
  4.    else
  5.       me.Label_Criteria.Visible = false
  6.    end if
'~~~~~~~~~~~~~~~~~~

I have used
Me.Filter
as an easy way of showing the report filter (if there is one). Personally, I construct a friendly string showing report criteria to display in the page footer section

for the Difference between + and & ... well that is another long discussion. In a nutshell, anytime you use + then everything in the clause (or between parentheses) has to be filled out or the answer is null. Using & to concatenate gets whatever is there, null or not
Nov 12 '15 #3

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

Similar topics

15
by: shaqattack1992-newsgroups | last post by:
Hello Everyone, Let me explain my problem. I have included 2 dashes between each pair of records to make it easier to see what goes together. In reality, it is just a long list of results...
2
by: Sped | last post by:
Hi, I'm looking for some code to monitor for when an external drive is connected to a computer (USB ThumbDrive, External Hard Drive, etc.) and is assigned a drive letter. I'd want my code to...
5
by: josecruz | last post by:
Hello, I have looked all over on the previous postings to attempt to solve a problem that I have when generating a report. The report provides counts and averages form several queries that are...
1
by: dfw1417 | last post by:
I have used a query and report filter to return records related to a specific account id. I want to print a report including only the latest 6 records out of the set returned by the record filter. I...
1
by: Doug | last post by:
What is the simplest way to make a report where only the records where a field matches a certain date are included, and the user first selects that date (from form or popup)? (I can write the SQL...
3
by: Pixel.to.life | last post by:
All, A question on JIT debugging with VS2005. I have a managed app that builds great on one machine (Vista Home basic, VS2005, JIT enabled for managed/unmanaged code). I can also debug it...
0
by: munkee | last post by:
Hi all, This would normally be quite simple however for some reason I can not getting working. My code to open my report filtered to a primary key is as follows: Case "Full record"...
6
Midzie
by: Midzie | last post by:
Hi All, if anyone could help me with my codes. I have a form with txtStartDate, txtEndDate, with a listbox lstWorkSLY and a cmdRunExtract button. I wanted to query records filtering txtStartDate to...
1
by: GanerDouglas | last post by:
I am recieving the error code: object required when assigning a value to a varible. I am working on a class assignment and code simular to this is used many times in my document and I can't find the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.