473,671 Members | 2,566 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pulling report with two criteria and date; type mismatch on preview

2 New Member
Hello –

I am still new to Access and I am currently working on debugging some code. I have a form with the following:

Employee Name (combo with select all choice)
Task (combo with select all choice)
Begin date (txt)
End Date (txt)

Both of the combo boxes are pulling from separate union queries

I am trying to get the form to pull a report depending on what criteria is chosen in the form. It works fine if you choose all employees/all tasks, one employee/all tasks, or all employees/one task, but if I try to pull one employee/one task, I get a type mismatch error. (no error code, just a msgbox that states type mismatch). Both of the combo boxes have an ID number(autonumb er) and name (txt) fields. I have used -1 in both of the ID's fields for select all employees/tasks.

Here is my code, please let me know how it looks overall and if there is anything I can improve on. I am still learning :) I am almost certain it has to do with line 43 (after the last else) but I have tried several different ways of wording it and nothing has worked.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Command11_Click()
  2. On Error GoTo Err_Command11_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim strWhereEmpl As String
  6.     Dim strWhereTask As String
  7.  
  8.     If IsNull(Me.cmbEmpl) Then
  9.         MsgBox "Select an employee to Preview."
  10.         Me.cmbEmpl.SetFocus
  11.         Exit Sub
  12.     End If
  13.  
  14.     If IsNull(Me.cmbTask) Then
  15.         MsgBox "Select a task to Preview."
  16.         Me.cmbTask.SetFocus
  17.         Exit Sub
  18.     End If
  19.  
  20.     'check to see that ending date is later than beginning date.
  21.     If IsDate(Begindate) And IsDate(Enddate) Then
  22.         If CDate(Enddate) < CDate(Begindate) Then
  23.             MsgBox "The ending date must be later than the beginning date."
  24.             Enddate.SetFocus
  25.             Exit Sub
  26.         End If
  27.     Else
  28.         MsgBox "Please use a valid date for the beginning date and the ending date values."
  29.         Exit Sub
  30.     End If
  31.  
  32.         strWhereEmpl = "EmplID = " & Forms![QRreportform]!cmbEmpl
  33.         strWhereTask = "TaskID = " & Forms![QRreportform]!cmbTask
  34.         stDocName = "QRsub"
  35.  
  36.     If Me.cmbEmpl = -1 And Me.cmbTask = -1 Then
  37.         DoCmd.OpenReport stDocName, acPreview
  38.     ElseIf Me.cmbTask = -1 Then
  39.         DoCmd.OpenReport stDocName, acPreview, , strWhereEmpl
  40.     ElseIf Me.cmbEmpl = -1 Then
  41.         DoCmd.OpenReport stDocName, acPreview, , strWhereTask
  42.     Else
  43.         DoCmd.OpenReport stDocName, acPreview, strWhereEmpl And strWhereTask
  44.     End If
  45.  
  46.  
  47. Exit_Command11_Click:
  48.     Exit Sub
  49.  
  50. Err_Command11_Click:
  51.     MsgBox Err.Description
  52.     Resume Exit_Command11_Click
  53.  
  54. End Sub
  55.  
You guys have already helped me out a lot by just reading your posts. Thanks and thanks again for your help!

Jonathon
Feb 4 '08 #1
3 1722
MMcCarthy
14,534 Recognized Expert Moderator MVP
The syntax on your criteria is not correct ..

Try this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command11_Click()
  2. On Error GoTo Err_Command11_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim strWhereEmpl As String
  6.     Dim strWhereTask As String
  7.  
  8.     If IsNull(Me.cmbEmpl) Then
  9.         MsgBox "Select an employee to Preview."
  10.         Me.cmbEmpl.SetFocus
  11.         Exit Sub
  12.     End If
  13.  
  14.     If IsNull(Me.cmbTask) Then
  15.         MsgBox "Select a task to Preview."
  16.         Me.cmbTask.SetFocus
  17.         Exit Sub
  18.     End If
  19.  
  20.     'check to see that ending date is later than beginning date.
  21.     If IsDate(Begindate) And IsDate(Enddate) Then
  22.         If CDate(Enddate) < CDate(Begindate) Then
  23.             MsgBox "The ending date must be later than the beginning date."
  24.             Enddate.SetFocus
  25.             Exit Sub
  26.         End If
  27.     Else
  28.         MsgBox "Please use a valid date for the beginning date and the ending date values."
  29.         Exit Sub
  30.     End If
  31.  
  32.         strWhereEmpl = "EmplID = " & Forms![QRreportform]!cmbEmpl
  33.         strWhereTask = "TaskID = " & Forms![QRreportform]!cmbTask
  34.         stDocName = "QRsub"
  35.  
  36.     If Me.cmbEmpl = -1 And Me.cmbTask = -1 Then
  37.         DoCmd.OpenReport stDocName, acPreview
  38.     ElseIf Me.cmbTask = -1 Then
  39.         DoCmd.OpenReport stDocName, acPreview, , strWhereEmpl
  40.     ElseIf Me.cmbEmpl = -1 Then
  41.         DoCmd.OpenReport stDocName, acPreview, , strWhereTask
  42.     Else
  43.         DoCmd.OpenReport stDocName, acPreview, strWhereEmpl & " And " & strWhereTask
  44.     End If
  45.  
  46.  
  47. Exit_Command11_Click:
  48.     Exit Sub
  49.  
  50. Err_Command11_Click:
  51.     MsgBox Err.Description
  52.     Resume Exit_Command11_Click
  53.  
  54. End Sub
  55.  
Feb 5 '08 #2
Nepenthen
2 New Member
That worked perfectly!! I knew it was something simple but I just couldn't figure it out. Thanks again for your help
Feb 5 '08 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
That worked perfectly!! I knew it was something simple but I just couldn't figure it out. Thanks again for your help
You're welcome.
Feb 5 '08 #4

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

Similar topics

1
17659
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
6
3314
by: Mike Conklin | last post by:
This one really has me going. Probably something silly. I'm using dcount for a report to determine the number of different types of tests proctored in a semester. My report is based on a parameter query which is the recordsource for the report. The parameter is <=. The query returns the correct amounts upto the date entered (no need for "between" dates here). There are 8 textboxes with dcounts; 2 other boxes Sum some of these
1
2260
by: Rinee | last post by:
Hi, I have a database of a bunch of contractors who have signed a safety agreement with us, their contact info, their insurance info, etc. Each was assigned an ID number as the main key. Each contractor agreement has an expiry date. I have a report that lists the contractors and a couple other relevant fields for reference for our company employees. But I don't want a contractor to appear on this report (which looks like a list of...
15
3131
by: sara | last post by:
I am stuck. I have a report that I use in multiple places, so I call it with varying parameters (using the Where Clause in the code). I preview the report, send it to snap, then close the preview (the user can go to the server to see the snap view). Print, snap, then close is the only way I can snap with a Where clause. If there is No data that meets the criteria, I can cancel the print,
19
21552
by: Lysander | last post by:
I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the date is more than 10 months out. The query runs fine, but I when I put the criteria of >10 I get 'Data Type mismatch' error. The code below is the original query. I have since put all the datediff bit in code, with all variables declared as date,...
7
4004
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
5
4014
by: DAHMB | last post by:
Hi all, Using Access 2007 I have a report called Sunday School Attendance based on a Query called qryAttendance the query is as follows: SELECT tblSundaySchoolAttendance.StudentID, tblSundaySchoolAttendance.AttendanceDate, . FROM tblSundaySchoolAttendance INNER JOIN ON tblSundaySchoolAttendance.StudentID=.StudentID;
17
5690
by: sharsy | last post by:
Hello guys, I would like some help in generating query criteria that will identify credit cards that have expired on an access database. The specific Field is formatted with a Data Type of 'Text' and has an input mask of '00/00', so all expiry dates are set out for example as 10/13 (which represents October 2013). I have hada brief go at trying to work it out, but I was unable to
14
7845
ollyb303
by: ollyb303 | last post by:
Hi, I am trying to create a dynamic crosstab report which will display number of calls handled (I work for a call centre) per day grouped by supervisor. I have one crosstab query (Query1) which has the following fields: SPID (supervisor ID), total:group by, as row heading Date, total:group by, as column heading Calls handled, total:sum, as value Date, total:where, criteria between and - this is taken from a form,
0
8402
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
8927
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
8825
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...
1
8605
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7445
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
4227
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
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.