How do I set the default value so that it includes all values?

G

Guest

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

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]));
 
P

Powderfinger

Cool!

I like the way you start off with TRUE so you don't have to worry about the
AND at the beginning. I have actually developed a function
(RemovePrefix(strPrefix, strFilter) As String) which removes the AND for me.
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.

Jack


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.
 
S

Steve Schapel

Chad,

Put the Criteria like this...
Like "*" & [Forms]![EMPHRS QUERY]![JobDesc] & "*"
 
S

Steve Schapel

Jack,
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.

As far as I know, this is not possible. You can't have just a space, or
a couple of spaces - Access will automatically remove them, and then it
will be Null. So, no harm done by what you do there, but also no use :).
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

My example assumed that the user would only have provision to enter a
date, and no time portion. In my experience, this is by far the most
common scenario. If there is provision to include the time component, I
use CDbl() in the place of CLng().
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.

Fair comments. I myself find there is a place for both approaches,
depending on the specific requirement. As for testing, if the form is
not open, you get prompted to type in the criteria, which I find fine
from a testing point of view.
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.

Interesting idea. By the way, you can refer to a form control in the
Control Source of a textbox on the report. For example, I would quite
often have a textbox in the report header with something like this in
its Control Source...
=[Forms]![Reports]![Sport] & " Points Tables for " &
Format([Forms]![Reports]![DateFrom],"dd-mmm\yy") & " to "
Format([Forms]![Reports]![DateTo],"dd-mmm\yy")
 
G

Guest

Steve,

I adjusted the query criteria like you said, and everything worked well,
except that it seems like there are too many fields and too many records.
Now whenever I run the query, or even when I try to open the query it says
that there is not enough memory. Any ideas?

Sept

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
 
S

Steve Schapel

Chad,

A "not enough memory" error when trying to run a query usually does not
mean "not enough memory" :). It usually means there is a mistake in
the query design that makes it impossible to evaluate.

I expect that because of the approach we have been taking to this query,
by now Access will have moved all your criteria around to handle the Is
Null situation, which thus makes it hard to understand. I think it
would be good to discard what you have done, and start the query design
fresh. Re-enter the Criteria as we have discussed, close and save, and
try again. If it's still not working, go back to design view, select
SQL from the View menu, and copy/paste the SQL view of the query into
your reply here, and I'll see if I can see.
 

Ask a Question

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.

Ask a Question

Top