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. -
Private Sub Command11_Click()
-
On Error GoTo Err_Command11_Click
-
-
Dim stDocName As String
-
Dim strWhereEmpl As String
-
Dim strWhereTask As String
-
-
If IsNull(Me.cmbEmpl) Then
-
MsgBox "Select an employee to Preview."
-
Me.cmbEmpl.SetFocus
-
Exit Sub
-
End If
-
-
If IsNull(Me.cmbTask) Then
-
MsgBox "Select a task to Preview."
-
Me.cmbTask.SetFocus
-
Exit Sub
-
End If
-
-
'check to see that ending date is later than beginning date.
-
If IsDate(Begindate) And IsDate(Enddate) Then
-
If CDate(Enddate) < CDate(Begindate) Then
-
MsgBox "The ending date must be later than the beginning date."
-
Enddate.SetFocus
-
Exit Sub
-
End If
-
Else
-
MsgBox "Please use a valid date for the beginning date and the ending date values."
-
Exit Sub
-
End If
-
-
strWhereEmpl = "EmplID = " & Forms![QRreportform]!cmbEmpl
-
strWhereTask = "TaskID = " & Forms![QRreportform]!cmbTask
-
stDocName = "QRsub"
-
-
If Me.cmbEmpl = -1 And Me.cmbTask = -1 Then
-
DoCmd.OpenReport stDocName, acPreview
-
ElseIf Me.cmbTask = -1 Then
-
DoCmd.OpenReport stDocName, acPreview, , strWhereEmpl
-
ElseIf Me.cmbEmpl = -1 Then
-
DoCmd.OpenReport stDocName, acPreview, , strWhereTask
-
Else
-
DoCmd.OpenReport stDocName, acPreview, strWhereEmpl And strWhereTask
-
End If
-
-
-
Exit_Command11_Click:
-
Exit Sub
-
-
Err_Command11_Click:
-
MsgBox Err.Description
-
Resume Exit_Command11_Click
-
-
End Sub
-
You guys have already helped me out a lot by just reading your posts. Thanks and thanks again for your help!
Jonathon
3 1722 MMcCarthy 14,534
Recognized Expert Moderator MVP
The syntax on your criteria is not correct ..
Try this: -
Private Sub Command11_Click()
-
On Error GoTo Err_Command11_Click
-
-
Dim stDocName As String
-
Dim strWhereEmpl As String
-
Dim strWhereTask As String
-
-
If IsNull(Me.cmbEmpl) Then
-
MsgBox "Select an employee to Preview."
-
Me.cmbEmpl.SetFocus
-
Exit Sub
-
End If
-
-
If IsNull(Me.cmbTask) Then
-
MsgBox "Select a task to Preview."
-
Me.cmbTask.SetFocus
-
Exit Sub
-
End If
-
-
'check to see that ending date is later than beginning date.
-
If IsDate(Begindate) And IsDate(Enddate) Then
-
If CDate(Enddate) < CDate(Begindate) Then
-
MsgBox "The ending date must be later than the beginning date."
-
Enddate.SetFocus
-
Exit Sub
-
End If
-
Else
-
MsgBox "Please use a valid date for the beginning date and the ending date values."
-
Exit Sub
-
End If
-
-
strWhereEmpl = "EmplID = " & Forms![QRreportform]!cmbEmpl
-
strWhereTask = "TaskID = " & Forms![QRreportform]!cmbTask
-
stDocName = "QRsub"
-
-
If Me.cmbEmpl = -1 And Me.cmbTask = -1 Then
-
DoCmd.OpenReport stDocName, acPreview
-
ElseIf Me.cmbTask = -1 Then
-
DoCmd.OpenReport stDocName, acPreview, , strWhereEmpl
-
ElseIf Me.cmbEmpl = -1 Then
-
DoCmd.OpenReport stDocName, acPreview, , strWhereTask
-
Else
-
DoCmd.OpenReport stDocName, acPreview, strWhereEmpl & " And " & strWhereTask
-
End If
-
-
-
Exit_Command11_Click:
-
Exit Sub
-
-
Err_Command11_Click:
-
MsgBox Err.Description
-
Resume Exit_Command11_Click
-
-
End Sub
-
That worked perfectly!! I knew it was something simple but I just couldn't figure it out. Thanks again for your help
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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
|
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...
|
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,
|
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,...
| |
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
|
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;
|
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
|
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,
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |