G
Guest
Thanks a lot Steve, that is exactly as I want it
CurtainMary
CurtainMary
Steve Schapel said:Sept,
Thanks. I really don't understand why you have not followed my
recommendation. Did you try it, and it didn't work as you needed? My
recommendation is standard procedure for this type of situation. So, in
the Criteria of the EMPNO field in your query, instead of this...
[Forms]![EMPHRS QUERY]![EMPNO]
replace it with this...
[Forms]![EMPHRS QUERY]![EMPNO] Or [Forms]![EMPHRS QUERY]![EMPNO] Is Null
In the Criteria of the DATE field in your query, instead of this...
Between [Forms]![EMPHRS QUERY]![START DATE] And [Forms]![EMPHRS
QUERY]![END DATE]
replace it with this...
Between [Forms]![EMPHRS QUERY]![START DATE] And [Forms]![EMPHRS
QUERY]![END DATE] Or [Forms]![EMPHRS QUERY]![START DATE] Is Null Or
[Forms]![EMPHRS QUERY]![END DATE] Is Null
In the Criteria of the JOBNO field in your query, instead of this...
[Forms]![EMPHRS QUERY]![JOBNO]
replace it with this...
[Forms]![EMPHRS QUERY]![JOBNO] Or [Forms]![EMPHRS QUERY]![JOBNO] Is Null
Etc....
After you save this query, if you open it again in design view, you will
probably see that Access has re-arranged the criteria you have entered,
to satisfy its own requirements - don't worry about this, it will work fine.
--
Steve Schapel, Microsoft Access MVP
SELECT EMPHRS.EMPNO, EMPHRS.DATE, EMPHRS.JOBNO, EMPHRS.JOBCODE, EMPHRS.DEPT,
EMPHRS.TOOLNO, EMPHRS.TIME, EMPHRS.ITEMNO, EMPHRS.JOBDESC
FROM EMPHRS
WHERE (((EMPHRS.EMPNO)=[Forms]![EMPHRS QUERY]![EMPNO]) AND ((EMPHRS.DATE)
Between [Forms]![EMPHRS QUERY]![START DATE] And [Forms]![EMPHRS QUERY]![END
DATE]) AND ((EMPHRS.JOBNO)=[Forms]![EMPHRS QUERY]![JOBNO]) AND
((EMPHRS.JOBCODE)=[Forms]![EMPHRS QUERY]![JOBCODE]) AND
((EMPHRS.DEPT)=[Forms]![EMPHRS QUERY]![DEPT]) AND
((EMPHRS.TOOLNO)=[Forms]![EMPHRS QUERY]![TOOLNO]) AND
((EMPHRS.TIME)=[Forms]![EMPHRS QUERY]![TIME]) AND
((EMPHRS.ITEMNO)=[Forms]![EMPHRS QUERY]![ITEMNO]) AND
((EMPHRS.JOBDESC)=[Forms]![EMPHRS QUERY]![JOBDESC]));
Steve Schapel said:Powder,
This is good. For the record, her's how I would do the same thing, but
really the same concept, just a slightly different syntax, and possibly
a little simpler...
Dim strFilter As String
strFilter = "TRUE"
If Not IsNull(Me.LName) Then
strFilter = strFilter & " And [LNAME] = '" & Me.LName & "'"
End If
If Not IsNull(Me.FName) Then
strFilter = strFilter & " And [FNAME] = '" & Me.FName & "'"
End If
If Not IsNull(Me.CID) Then
strFilter = strFilter & " And [CID] = " & Me.CID
End If
If Not IsNull(Me.StartDate + Me.EndDate) Then
strFilter = strFilter & " And [IDate] Between " &
CLng(Me.StartDate) & " And " & CLng(Me.EndDate)
End If
We have our filter with just what we want.
--
Steve Schapel, Microsoft Access MVP
Here's how I do it, but there's probably a better way:
Dim strFilter As String
Dim stsLNAMEFilter As String
Dim strFNAMEFilter As String
Dim strCIDFilter As String
Dim strDateFilter As String
If Len(Trim(Me.LName)) > 0 Then strLastNameFilter = "[LNAME] Like '" &
Me.LName & "*'"
If Len(Trim(Me.FName)) > 0 Then strFirstNameFilter = "[FNAME] = '" &
Me.FName & "'"
If IsNumeric(Me.CID) Then strCIDFilter = "[CID] = '" & Me.CID
If IsDate(Me.StartDate) And IsDate(Me.EndDate) then strDateFilter = "[IDate]
Between #" & Format$(Me.StartDate, "mm/dd/yyyy") & "# AND #" &
Format$(Me.EndDate, "mm/dd/yyyy") & "#"
' now that I have all the filters I connect them with an AND:
If Len(Trim(strLastNameFilter)) > 0 Then strFilter = strLastNameFilter
If Len(Trim(strFirstNameFilter)) > 0 Then strFilter = strFilter & " " &
"AND" & " " & strFirstNameFilter
If Len(Trim(strCIDFilter )) > 0 Then strFilter = strFilter & " " & "AND" &
" " & strCIDFilter
If Len(Trim(strDateFilter )) > 0 Then strFilter = strFilter & " " & "AND" &
" " & strDateFilter
' now I have to get rid of the "AND" if it is the first three characters of
the filter
If Left(strFilter , 3) = "AND" Then
strFilter = Right(strFilter , Len(strFilter ) - 3)
End If
We have our filter with just what we want.
I use If Len(Trim(Me.LName)) > 0 instead of IsNull because if the user
happens to leave a couple of spaces in there, it will consider it null.
Curious how you are using CLng() for the dates. Won't this convert the time
associated with the date also? All dates have times associated with them,
although in most cases it's zero which represents 12 midnight I believe. My
point is, say the start date is 2/4/2006 12:01 AM , then your routine will
miss dates of 2/4/2006 12:00 AM
I just don't like imbedding the form controls in the query. First, it makes
it annoying to debug since the form must be open in order for the query to
work. Second, if you want to use the same query for other forms/reports it's
useless.
Another thing I almost always do is create a one-record table (e.g .
tblReportParameters ) for the report options form. Access/VBA just works
well with tables , that's what everything revolves around. In this way I can
create a report based upon this table and insert it as a subReport in the
report header so the user knows what parameters he chose.
Steve Schapel said:Chad,
Put the Criteria like this...
Like "*" & [Forms]![EMPHRS QUERY]![JobDesc] & "*"
--
Steve Schapel, Microsoft Access MVP
Thanks Steve,
I must have missed something before, but after you clearly spelled it out to
me, I finally got it. One other question though if you don't mind.
Do wildcard characters work the same? For example, one of the fields is
jobdesc. Now say I want to run a query on any job desc with the word 'clean'
in it, how would I do that?
Thanks,
Chad
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.