473,394 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Trying to set up a query

Hi all,

I'm trying to set up a query that runs from a command button on a form
(simple enough so far), what I want the query to do is take values
from the fields on the form (seven fields in total) but sometimes not
all the fields will be filled. If a field is empty then the
assumption is that no filter will be applied to that field in the
query and should return all results within the limits of the other
field in the query.

How would I set up a query to take a value as a wildcard (*) if no
data is entered into the field?

Probably a simple answer but I think I'm currently suffering from
putty brain or something.

Thanks, Dean...

Jun 7 '07 #1
5 2037
On Jun 7, 3:16 pm, DeanL <deanpmlonghu...@yahoo.comwrote:
Hi all,

I'm trying to set up a query that runs from a command button on a form
(simple enough so far), what I want the query to do is take values
from the fields on the form (seven fields in total) but sometimes not
all the fields will be filled. If a field is empty then the
assumption is that no filter will be applied to that field in the
query and should return all results within the limits of the other
field in the query.

How would I set up a query to take a value as a wildcard (*) if no
data is entered into the field?

Probably a simple answer but I think I'm currently suffering from
putty brain or something.

Thanks, Dean...
Here's some working code that filters a schedule of events (Course
Sections) on (optionally) Date/Time and (Optionally) an Instructor's
Department or ID. Basically I check the length of the form fields
("Me...") and if 0 skip appending the where clause onto the filter...

<compiled VBA>

Public Sub SetFilter()
Dim wkFilter As String
Dim wkDate As String
Dim wkTime As String
Dim wkDept As String
Dim wkInst As String

On Error GoTo ProcErr

Me.Filter = ""
Me.FilterOn = False

If (Len(Me.usSetDate) 0) Then
wkDate = CDate(DatePart("m", Me.usSetDate) & "/" & DatePart("d",
Me.usSetDate) & "/" & DatePart("yyyy", Me.usSetDate))
wkTime = CDate(DatePart("h", Me.usSetDate) & ":" & DatePart("n",
Me.usSetDate) & ":" & DatePart("s", Me.usSetDate) & IIf(Right$
(Me.usSetDate, 1) = "M", Right$(Me.usSetDate, 2), ""))

Select Case (wkTime)
Case "12:00:00 AM"
wkFilter = "([EventDate] = #" & wkDate & "#) AND "
Case Else
wkFilter = "([EventDate] = #" & wkDate & "#) AND " & _
"([EventStartTime] <= #" & wkTime & "#) AND " & _
"([EventEndTime] >= #" & wkTime & "#) AND "
End Select
End If

wkDept = Me.usSetDept
wkInst = Me.usSetInst

If (wkDept <"{ALL}") Then
If (Len(wkDept) 0) Then
wkFilter = wkFilter & "([Dept] = '" & wkDept & "') AND "
Else
wkFilter = wkFilter & "(IsNull([Dept]) = True) AND "
End If
End If

If (wkInst <"{ALL}") Then
If (Len(wkInst) 0) Then
wkFilter = wkFilter & "([Instructor] = '" & wkInst & "') AND "
Else
wkFilter = wkFilter & "(IsNull([Instructor]) = True) AND "
End If
End If

If (Len(wkFilter) 0) Then
Me.Filter = Mid$(wkFilter, 1, Len(wkFilter) - 5)
Me.FilterOn = True
End If

ProcExit:
Exit Sub

ProcErr:
Select Case Err
Case 0:
Resume Next
Case Else
Forms.frmMain.Prog 0, "SetFilter Error: " & Err & " " &
Err.Description & " " & Now()
Forms.frmMain.ErrLog "SetFilter", Err, Err.Description
Resume ProcExit
End Select
End Sub

</compiled VBA>

Hopefully there's not too much obscure crap in there to confuse yas.
In this sample, most of the the form fields are drop down lists of
distinct values in the Table.RecordSource UNIONed with the literal
"{ALL}" (the curly braces sort this value to the top of the lists). If
the field is {ALL} then that phrase of the filter is skipped.

Lucks to yas pal!

Ron, King of Chi

Jun 7 '07 #2
you need to put the field reference from the form in the query criteria i.e
forms!formname!fieldname to handle null vales you need to put
forms!formname!fieldname = null in the criteria. So for one query field you
will have two rows of crtieria one for the value the other for no value. If
you want to add a second query field with crteria no you will need four rows
of criteria, one for the value of field one and field two, the next for one
value and one null, another for it reversed and a fourth for both null.
Hopefully I explained it so you can understand

"DeanL" <de*************@yahoo.comwrote in message
news:11**********************@g37g2000prf.googlegr oups.com...
Hi all,

I'm trying to set up a query that runs from a command button on a form
(simple enough so far), what I want the query to do is take values
from the fields on the form (seven fields in total) but sometimes not
all the fields will be filled. If a field is empty then the
assumption is that no filter will be applied to that field in the
query and should return all results within the limits of the other
field in the query.

How would I set up a query to take a value as a wildcard (*) if no
data is entered into the field?

Probably a simple answer but I think I'm currently suffering from
putty brain or something.

Thanks, Dean...

Jun 7 '07 #3
"Scott" <a@awrote in
news:46**********************@news.aliant.net:
you need to put the field reference from the form in the query
criteria i.e forms!formname!fieldname
The first part is correct.

to handle null vales you
need to put forms!formname!fieldname = null in the criteria.
that is wrong. it needs to be
forms!formname!fieldname IS null

there is a difference between = and IS null.
So for one query field you will have two rows of crtieria one
for the value the other for no value. If you want to add a
second query field with crteria no you will need four rows of
criteria, one for the value of field one and field two, the
next for one value and one null, another for it reversed and a
fourth for both null. Hopefully I explained it so you can
understand

"DeanL" <de*************@yahoo.comwrote in message
news:11**********************@g37g2000prf.googlegr oups.com...
>Hi all,

I'm trying to set up a query that runs from a command button
on a form (simple enough so far), what I want the query to do
is take values from the fields on the form (seven fields in
total) but sometimes not all the fields will be filled. If a
field is empty then the assumption is that no filter will be
applied to that field in the query and should return all
results within the limits of the other field in the query.

How would I set up a query to take a value as a wildcard (*)
if no data is entered into the field?

Probably a simple answer but I think I'm currently suffering
from putty brain or something.

Thanks, Dean...




--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jun 7 '07 #4
On Jun 7, 2:15 pm, Bob Quintal <rquin...@sPAmpatico.cawrote:
"Scott" <a@awrote innews:46**********************@news.aliant.net:
you need to put the field reference from the form in the query
criteria i.e forms!formname!fieldname

The first part is correct.

to handle null vales you
need to put forms!formname!fieldname = null in the criteria.

that is wrong. it needs to be
forms!formname!fieldname IS null

there is a difference between = and IS null.
So for one query field you will have two rows of crtieria one
for the value the other for no value. If you want to add a
second query field with crteria no you will need four rows of
criteria, one for the value of field one and field two, the
next for one value and one null, another for it reversed and a
fourth for both null. Hopefully I explained it so you can
understand
"DeanL" <deanpmlonghu...@yahoo.comwrote in message
news:11**********************@g37g2000prf.googlegr oups.com...
Hi all,
I'm trying to set up a query that runs from a command button
on a form (simple enough so far), what I want the query to do
is take values from the fields on the form (seven fields in
total) but sometimes not all the fields will be filled. If a
field is empty then the assumption is that no filter will be
applied to that field in the query and should return all
results within the limits of the other field in the query.
How would I set up a query to take a value as a wildcard (*)
if no data is entered into the field?
Probably a simple answer but I think I'm currently suffering
from putty brain or something.
Thanks, Dean...

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account fromhttp://www.teranews.com
Hi again guys,

The basis of my query is to show records filtered by any or all of the
following:

Cost (Between Min and Max values)
Fiscal Year
Award Date (Between Min and Max values)
Reviewer Name
Project Engineer

The problems start to arise when I select certain fields but need to
leave the date fields empty, how would I then return the values in the
query for ALL dates?

Most of the other fields have no problem substituting a wildcard
character for their value. This query is used to count the total
number of projects for a given Fiscal Year and then 2 other queries
are used, one to count those On Time and On Budget and a 3rd query to
count those not On Time On Budget.

Regards, Dean...

Jun 8 '07 #5
DeanL <de*************@yahoo.comwrote in
news:11**********************@d30g2000prg.googlegr oups.com:
On Jun 7, 2:15 pm, Bob Quintal <rquin...@sPAmpatico.cawrote:
>"Scott" <a@awrote
innews:46**********************@news.aliant.net :
you need to put the field reference from the form in the
query criteria i.e forms!formname!fieldname

The first part is correct.

to handle null vales you
need to put forms!formname!fieldname = null in the
criteria.

that is wrong. it needs to be
forms!formname!fieldname IS null

there is a difference between = and IS null.
So for one query field you will have two rows of crtieria
one for the value the other for no value. If you want to
add a second query field with crteria no you will need four
rows of criteria, one for the value of field one and field
two, the next for one value and one null, another for it
reversed and a fourth for both null. Hopefully I explained
it so you can understand
"DeanL" <deanpmlonghu...@yahoo.comwrote in message
news:1181247408.576800.313000
@g37g2000prf.googlegroups.com...
>Hi all,
>I'm trying to set up a query that runs from a command
button on a form (simple enough so far), what I want the
query to do is take values from the fields on the form
(seven fields in total) but sometimes not all the fields
will be filled. If a field is empty then the assumption
is that no filter will be applied to that field in the
query and should return all results within the limits of
the other field in the query.
>How would I set up a query to take a value as a wildcard
(*) if no data is entered into the field?
>Probably a simple answer but I think I'm currently
suffering from putty brain or something.
>Thanks, Dean...

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account fromhttp://www.teranews.com

Hi again guys,

The basis of my query is to show records filtered by any or
all of the following:

Cost (Between Min and Max values)
Fiscal Year
Award Date (Between Min and Max values)
Reviewer Name
Project Engineer

The problems start to arise when I select certain fields but
need to leave the date fields empty, how would I then return
the values in the query for ALL dates?

Most of the other fields have no problem substituting a
wildcard character for their value. This query is used to
count the total number of projects for a given Fiscal Year and
then 2 other queries are used, one to count those On Time and
On Budget and a 3rd query to count those not On Time On
Budget.

Regards, Dean...
the way I'd do this is to create the query programatically in
code.

the other way is to setup your criteria as follows:
cost:
between nz(Forms!myform!minimumcost,0) and nz(Forms!myForm!
maximumCost,99999999999)
Fiscal year:
like nz(Forms!myform!fiscalYear, "*")
Award Date:
Between nz(Forms!myForm!startdate,#01/01/1776#) and nz(Forms!
myForm!enddate,#31/12/9999#)

The last two should mimic fiscal year.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jun 8 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: KevLow | last post by:
Hi, Hope some kind soul can help me out here.. I'm trying to programmatically modify the column headings of a crosstab query such that it can be dynamic based on user specified period (Month...
2
by: ecoulson123 | last post by:
I am using Access 2000. I am trying to summarize numeric data from a large database. The problem is that I need the summarization functions to ignore "junk" data, defined in a couple ways. ...
8
by: Jerome Ranch | last post by:
Okay So I've got pivot tables setup in Access 2003. Only about 30K records in the current 2005 databases...the pivots summarize the info in a number of nice ways. I need to get the pivot tables...
1
by: bob.hughes | last post by:
I'm trying to write a query that will find multiple transactions that take place within a pre-determined time limit. I can easily compute the time between adjacent transactions and then judge...
9
by: Jeremy | last post by:
I have a situation where i am trying to run two query's and retrieve one record from each query, then using Union combine them into one recordset. The First Query is strait forward and should just...
0
by: Luke Herbert | last post by:
I am very new to C# and have been trying to get to grips with it by writing a small tool to detect a USB key being inserted and then backup user specified files to the key. I have written some...
5
by: kkddrpg | last post by:
the database looks like this the database is called username_tpp (not really just using username as a sub) the table is called home it has field 1 : varchar(50) | latin1_swedish_ci | no...
1
by: rfranzl | last post by:
Hello, I need some help, I have about 200 databases that are copies of an original database that has a similiar table in all of the databases, called "tblCodebook". What I am trying to do is to...
8
by: Trevor2007 | last post by:
I am trying to hard code the following select query into a select case statement ie (case1 <statment>, case 2 <statment>) but I getteing Compiler error: expected line number or label, or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.