473,769 Members | 6,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2079
On Jun 7, 3:16 pm, DeanL <deanpmlonghu.. .@yahoo.comwrot e:
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.usSetDa te) 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.usSet Date, 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.P rog 0, "SetFilter Error: " & Err & " " &
Err.Description & " " & Now()
Forms.frmMain.E rrLog "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.RecordSou rce 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.comwrot e in message
news:11******** **************@ g37g2000prf.goo glegroups.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.comwrot e in message
news:11******** **************@ g37g2000prf.goo glegroups.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...@sPAmp atico.cawrote:
"Scott" <a@awrote innews:46****** *************** *@news.aliant.n et:
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.comwrot e in message
news:11******** **************@ g37g2000prf.goo glegroups.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.co m
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.comwrot e in
news:11******** **************@ d30g2000prg.goo glegroups.com:
On Jun 7, 2:15 pm, Bob Quintal <rquin...@sPAmp atico.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.comwrot e in message
news:118124740 8.576800.313000
@g37g2000prf.go oglegroups.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.co m

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,999 99999999)
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
3108
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 Year to Month Year) So far i have tried to use the following code: //
2
1766
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. Assume an excerpt of the database table looks like this: Lot SerialNumber Status Error 101 001 Good .3 002 Good .2 003 Mach Fail .4
8
4871
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 into a document so I can distribute the tables, as is, as an electronic report (without the detailed data) So I export to rtf and xls, and I get an error that there is a too much information. I don't want all the data, just the summary table!
1
1326
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 whether they fall within the time limit, but I can't figure out a way to do this for three or more transactions. Does anybody know how to do this?
9
2935
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 return the matching record however the second query needs to find a random record and return it. The union is causing me some trouble. It seems that any method i try to find a random record just causes an error. Here is an example of a query...
0
4091
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 code and been able to construct a WMI query and can even get the output of this query to display to the console but not to a TextBox on my form. I fear it is embarassingly obvious but having looked at a whole heap of books (not read them in their...
5
1476
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 attributes | null = no | default = (nothing) | extra = (nothing) | action = primary key | comments = h
1
1994
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 create a macro that will go into each of the 200 databases, run an identical "unmatched query" to find any records that might be in one of the copies of the "tblCodebook". There is a shared primary key in the "tblCodebook" which is a StoryID and...
8
4479
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 statement or end of statement on my select line , with and without the pertentheses at the end of my where clause. here is what I have, the query functions proporly in the access query builder. "SELECT .Date, .IDNumber, .Time," _ & "...
0
9587
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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
10211
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
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
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
5298
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...
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.