473,401 Members | 2,125 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,401 software developers and data experts.

Filtering Report With Text Boxes and Combo List

Hi,

I want to create a form that filters a report that is between a date range, and includes only the data for the item selected in the combo box.

For example, I am creating a time manager report, and want to have a report created that is between Date1 and Date2 and is for Person1. If no person is selected, it runs for everyone. If no date range is selected, it runs for all dates.

I created two command buttons, one is for running the report for the date range, and one is for running the report only for the selected person in the combo box. They both work individually, however I am have trouble combining the two. Whenever I want to combine the two conditions in the conditions section of the OpenCommand, I get errors. I tried combine the two with an &, but get "Runtime Error 3075". When I try combining the two conditions with AND, I get "Runtime Error 13, Type Mismatch".

Below is the code for the two command buttons.

Command Button 1: Date Ranges. I took this from http://allenbrowne.com/casu-08.html , and it works perfectly

Command Button 2: Combo Box. The variables are: Report Name:TIMESHEET1, Data-Table for report: TIMESHEET1, combobox: cmbStaff

Expand|Select|Wrap|Line Numbers
  1. If IsNull(Me![cmbStaff]) Then
  2.   DoCmd.OpenReport "TIMESHEET1", acViewPreview
  3.   Else
  4. DoCmd.OpenReport "TIMESHEET1", acViewPreview, , "TIMESHEET1.Staff='" & Me![cmbStaff] & "'", acWindowNormal
  5. End If
  6.  
The code for Command Button2 works like this: if no-one is selected in the combo box, it creates the form with no filter. If someone is selected, it filters for only instances where that person appears.

I tried combining the two with the code below. However, as mentioned before, I keep getting errors.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdPreview_Click()
  2.  
  3. 'On Error GoTo Err_Handler      'Remove the single quote from start of this line once you have it working.
  4.     'Purpose:       Filter a report to a date range.
  5.     'Documentation: http://allenbrowne.com/casu-08.html
  6.     'Note:          Filter uses "less than the next day" in case the field has a time component.
  7.     Dim strReport As String
  8.     Dim strDateField As String
  9.     Dim strWhere As String
  10.     Dim strStaff As String
  11.     Dim lngView As Long
  12.     Const strcJetDate = "\#mm\/dd\/yyyy\#"  'Do NOT change it to match your local settings.
  13.  
  14.     'DO set the values in the next 3 lines.
  15.     strReport = "TIMESHEET1"      'Put your report name in these quotes.
  16.     strDateField = "[Review_Date]" 'Put your field name in the square brackets in these quotes.
  17.     lngView = acViewPreview     'Use acViewNormal to print instead of preview.
  18.  
  19.     'Build the filter string.
  20.     If IsDate(Me.txtStartDate) Then
  21.         strWhere = "(" & strDateField & " >= " & Format(Me.txtStartDate, strcJetDate) & ")"
  22.     End If
  23.     If IsDate(Me.txtEndDate) Then
  24.         If strWhere <> vbNullString Then
  25.             strWhere = strWhere & " AND "
  26.         End If
  27.         strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtEndDate + 1, strcJetDate) & ")"
  28.     End If
  29.  
  30.     strStaff = "TIMESHEET1.Staff='" & Me![cmbStaff] & "'"
  31.  
  32.     'Close the report if already open: otherwise it won't filter properly.
  33.     If CurrentProject.AllReports(strReport).IsLoaded Then
  34.         DoCmd.Close acReport, strReport
  35.     End If
  36.  
  37.     'Open the report.
  38.     'Debug.Print strWhere        'Remove the single quote from the start of this line for debugging purposes.
  39.  
  40.    If IsNull(Me![cmbStaff]) Then
  41.   DoCmd.OpenReport "TIMESHEET1", acViewPreview, , strWhere
  42.   Else
  43. DoCmd.OpenReport "TIMESHEET1", acViewPreview, , strWhere & strStaff, acWindowNormal
  44. End If
  45.  

Any help is greatly appreciated.
Oct 27 '10 #1
1 2358
Nevermind, I fixed it.
Oct 27 '10 #2

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

Similar topics

0
by: Monir | last post by:
Hi guys, I made a database with two tables ( tblsender, tblreceiver) with one to many relationship. tblsender has sender_Id (pk) sender_name, address, phone, email etc. tblreceiver has...
4
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one...
2
by: jw01 | last post by:
I have a form in which there is one combo box and three text boxes: Combo Box: -> Item A -> Item B -> Item C TextBox1: TextBox2: ...
0
by: LaksM | last post by:
Hi, I need to create a combox/listbox with certain fixed width. In that I need to display large text. I can use Hscroll for list box. But, is there a way to display the text as tooltip/mouse over...
7
by: Ceebaby via AccessMonster.com | last post by:
Hi All Here's hoping someone can help me with this. I have a report based on a query where the criteria for 4 of the fields is set from an unbound form. I want the user to be able to select any...
9
by: Marianne160 | last post by:
Hi, I know there are various answers to this problem available on the web but none of them seem to work for me. I am using Access 2003 to make a form to look up data from a table. I have so far...
1
by: Hiker68 | last post by:
Hello, I am very new at Access & VBA so I hope you understand what I am asking. I have a form that displays information about an apartment building. I created a combo box to list all of the...
3
by: dblack64 | last post by:
I am working in Access 2007. I have a form named Master Terms List that contains 4 bound text boxes and 7 cascading combo boxes. The bound text boxes have data sources from a table named Termslist. ...
3
by: slenish | last post by:
Hello, Im having trouble getting a form to fill in mulitple text boxes based on a query. What I have is a form where I can enter the Criteria information to look up a record. You have to...
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: 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...
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
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.