473,395 Members | 1,468 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,395 software developers and data experts.

Report "Filtering" with User entered Data

Alright, I give up! I'm asking the experts. I have created a database that calculates PTO for employees. I need to be able to cache the report by user entered dates and specific employee names. I have been able to get the dates to work with the following VBA script:
Expand|Select|Wrap|Line Numbers
  1. ..
  2. Private Sub cmdOK_Click()
  3.  
  4. Dim strReport As String     'Name of report to open.
  5.     Dim strField As String      'Name of your date field.
  6.     Dim strWhere As String      'Where condition for OpenReport.
  7.     Const conDateFormat = "\#mm\/dd\/yyyy\#"
  8.  
  9.     strReport = "PTO Form"
  10.     strField = "DateUsed"
  11.  
  12.     If IsNull(Me.txtStartDate) Then
  13.         If Not IsNull(Me.txtEndDate) Then   'End date, but no start.
  14.             strWhere = strField & " <= " & Format(Me.txtEndDate, conDateFormat)
  15.         End If
  16.     Else
  17.         If IsNull(Me.txtEndDate) Then       'Start date, but no End.
  18.             strWhere = strField & " >= " & Format(Me.txtStartDate, conDateFormat)
  19.         Else                                'Both start and end dates.
  20.             strWhere = strField & " Between " & Format(Me.txtStartDate, conDateFormat) _
  21.                 & " And " & Format(Me.txtEndDate, conDateFormat)
  22.         End If
  23.  
  24.     End If
  25.  
  26.  
  27.  
  28.     ' Debug.Print strWhere                  'For debugging purposes only.
  29.  
  30.  
  31.     DoCmd.OpenReport strReport, acViewPreview, , strWhere
  32.  
  33.  
  34. End Sub
However, the field that I have also put in, EmpName, which is a combo box, I cannot get it to filter by. Please help :)
Feb 8 '07 #1
9 2368
nico5038
3,080 Expert 2GB
A combobox can be referred to like other fields like:
Me.comboname
There's however a catch as the combo can hold multiple columns and only the "bound" coulmn (see the Data property tab) will be returned. When you need e.g. the second column use:
Me.comboname.column(1)
The index is "zero based" and will start with 0 for the forst column, etc.

Nic;o)
Feb 9 '07 #2
NeoPa
32,556 Expert Mod 16PB
I looked through your code, which illustrates some good understanding of Date filtering (a concept most people struggle with badly). One minor point, the (\) is not necessary before the (/) for the format string (It's right for the (#)s though :) - Nice).
Anyway, Please check out this tutorial (Example Filtering on a Form.) for help with your filtering. If you find you're still stuck after that then please come back and explain where your difficulty(ies) lie and we'll do what we can to help.
Feb 10 '07 #3
I had tried using the "filter a form" instructional, and I just can't seem to get it to take. I am struggling with where I should add the additional filter to the code and how exactly to add it. I've been able to do so much with access, that I know I must be stumbling on a mundane block! Please advise :)

Thanks
Feb 13 '07 #4
NeoPa
32,556 Expert Mod 16PB
Can you tell me which chapter you got up to and what your confusion is exactly?
You know there is an example database attached with the finished article in don't you?
Feb 13 '07 #5
I have read through all seven chapters about 5 times now and I'm getting stuck at the filter portion. I don't have a specific filter set for this form, not sure how to do it so that it would leave it open for change every time the form pops up...
The mail problem is that I am not sure where to put the extra filter into the code and how to do so...
Feb 13 '07 #6
NeoPa
32,556 Expert Mod 16PB
I'm afraid you're going to have to be a lot clearer than that. What you say makes very little sense on its own (If I had your database in front of me then it might, but I don't). You need to explain in clear simple English, what you need.
What does this even mean ? :confused:
The mail problem is that I am not sure where to put the extra filter into the code and how to do so...
Feb 13 '07 #7
Rabbit
12,516 Expert Mod 8TB
I think it's just a typo. Mail = Main. But other that that, I too am confused on exactly what they want.
Feb 13 '07 #8
All I want is to add another filter into the code that I posted above. The combo box that I have in the form is "Combo6" and it reflects the text box "EmpName" on the report that is generated from the aforementioned form. When trying to use the instructions, it is not bound to a specific table. It is just a form with a report tied to it that is limited by selections made on that form. There is only one list in the combo box, not several different to choose from, they are all in text form within the combo box. Hopefully this helps a little further...
Feb 13 '07 #9
NeoPa
32,556 Expert Mod 16PB
Assuming the field in the underlying record source of the report is also called [EmpName] you would need something like :
Expand|Select|Wrap|Line Numbers
  1. ..
  2. Private Sub cmdOK_Click()
  3.  
  4. Dim strReport As String     'Name of report to open.
  5.     Dim strField As String      'Name of your date field.
  6.     Dim strWhere As String      'Where condition for OpenReport.
  7.     Const conDateFormat = "\#mm/dd/yyyy\#"
  8.  
  9.     strReport = "PTO Form"
  10.     strField = "DateUsed"
  11.  
  12.     If IsNull(Me.txtStartDate) Then
  13.         If Not IsNull(Me.txtEndDate) Then   'End date, but no start.
  14.             strWhere = strField & " <= " & Format(Me.txtEndDate, conDateFormat)
  15.         End If
  16.     Else
  17.         If IsNull(Me.txtEndDate) Then       'Start date, but no End.
  18.             strWhere = strField & " >= " & Format(Me.txtStartDate, conDateFormat)
  19.         Else                                'Both start and end dates.
  20.             strWhere = strField & " Between " & Format(Me.txtStartDate, conDateFormat) _
  21.                 & " And " & Format(Me.txtEndDate, conDateFormat)
  22.         End If
  23.  
  24.     End If
  25.  
  26.     If Not IsNull(Me!Combo6) Then
  27.         strWhere = "((" & strWhere & ") AND ([EmpName]='" & Me!Combo6 & "'))"
  28.     End If
  29.  
  30.  
  31.  
  32.     ' Debug.Print strWhere                  'For debugging purposes only.
  33.  
  34.  
  35.     DoCmd.OpenReport strReport, acViewPreview, , strWhere
  36.  
  37.  
  38. End Sub
Feb 25 '07 #10

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

Similar topics

4
by: Felicity | last post by:
Hello, I have the following basic XML file: <ProductX> <Settings> <FormA> <TextBox1> <value>ABC</value> </TextBox1>
1
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...
9
by: mooseshoes | last post by:
All: I'm using Access 2000 on a Windows XP platform. My goal is to use a form to gather user criteria which I will then parse into a useable SQL string. At this point I would like to open one...
8
by: Armando | last post by:
Here's one that's going to leave me bald before long - I have a report (no headers or footers, small detail section) that runs normally when I open it from the database window. When I run it...
2
by: Denise | last post by:
How do I get the report to not spend time pulling up the data when I'm going to bail out of the report anyway? Below is the code in my report. I first show the user a form where they can select...
8
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
0
by: Sheryl 37 | last post by:
Can any1 give me the coding for the following problem.....How to i filter data in Crystal Report using a combo option (e.g Company Name). There1 combo box for the Company, and a crystal report....
0
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...
2
by: jim190 | last post by:
I am relatively new to using VBA and am have been trying for two days to pass a user entered value to my report for filtering when opened. I have the following subroutine in the open event of my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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...

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.