473,563 Members | 2,662 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Report Filter: Using 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: syntax error (missing operator) in query expression". 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 26 '10 #1
0 1474

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.
11
3851
by: DP | last post by:
hi, i have a films table and form. i have a txt field in teh form called txtSearch , and i;ve created a query with all the film table fields in it. how can i get the query to load up, wth the required film infromation in it?? i've a query called qryFilmQuery
5
1994
by: John | last post by:
Hi I am using text boxes on a web form. How can I make it so users can insert values only in the format 99-99-99 ? Thanks Regards
2
3610
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
1597
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.
5
6724
by: Andrew Meador | last post by:
I have a form (Change Card List by Status) with a check box (cboNOT) and a list box (lstStatus). There is an Open Report button that opens a report (Report - Change Card List) which uses a query (SQL -Change Card List). What I want to do is have the form open the report where a filter is set to use the values from the check box AND the...
6
2547
by: noe1818 via AccessMonster.com | last post by:
Just a quick question about lines: Is it possible to connect a text box (e.g. txtbx1 to txtbx2 and txtbx2 to txtbx3) with lines where txtbx1,2,&3 move up or down according to their values? Like have access find the location of each txtbx and draw a line from it to the other textbox? Thanks --
2
1668
by: bellam31 | last post by:
I am using text boxes in Windows Mobile 6, and I just need to no how to get the text once the user has entered it. Im used to developing in Java where it would be 'textbox.getText();', can any one help me?
1
2035
by: tembil | last post by:
Hi, I'm designing a windows application in visual studio 2008 and connecting to oracle 10g XE but don't know how to add, update and delete records from my database using text boxes. Thanks in advance
3
2406
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...
0
7659
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7882
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. ...
0
8103
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...
1
7634
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7945
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5208
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...
0
3634
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...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2079
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

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.