473,625 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filtering Report With Text Boxes and Combo List

2 New Member
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 2399
Marie Gardner
2 New Member
Nevermind, I fixed it.
Oct 27 '10 #2

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

Similar topics

0
314
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 receiver_id (pk), sender_id (fk) receiver_name, address, phone, date, etc.
4
64582
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 determines the available options in the other. TERMINOLOGY Row Source: The table/query from which the Combo Box or List Box gets its values. Note: There are other types of row sources that can be used but for simplicity we will stick with Tables...
2
3612
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: TextBox3:
0
1604
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 text ? Need some help.
7
4003
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 combination of the combo boxes, some might not be selected etc etc. ie they may want to select the area and ward to show on the report but not the case officer or the property type
9
4986
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 created three combo boxes that cascade down from Name to Project to Date and when this has been chosen I have four textbox fields I want to display based on this selection. I tried linking the last combo box comboDate to update these fields after...
1
1728
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 apartment Units/numbers. Under neath the combo box I have 5 different text boxes for dates for construction. Examples of the dates are "start Date", "Application Date", "Completion Date". The user will populate these text boxes with the dates, as...
3
1508
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. The record source for the 7 cascading combo boxes is also the table Termslist. The names of the fields on form Master Terms List and the type of controls they are follows: Termslistmonth - text box DateReceived - text box Coordinator - combo box...
3
2409
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 enter the information in to 3 text boxes on the form. Then after your done a query will run pulling up the results. That part seems to work with no problem but what i cant get to work is instead of the query window popping up, have all of the the other...
0
8189
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8692
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7182
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.