this is a very basic question but i might be making it more complicated than it should be. if i were to have a query with the following code - SELECT Tbl1.ID, Tbl1.[First Name], Tbl1.[Last Name]
-
FROM Tbl1
-
WHERE (((Tbl1.ID)=[forms]![frmTest].[id]));
it will automatically pull whatever is in the frmTest's id value.
now, what if i decide that for a particular case i don't want the ID criteria? if frmTest is closed it will prompt me to enter in data to replace [forms!test.id]. if i changed the criteria to Nz([forms!test.id],0) it would fill in the criteria as zero without a prompt. so, instead of using zero, is there a command that can be used to tell the query not to use any criteria and run the query like as if there were nothing in the where statement?
this is also related to when i make a query def parameter in DAO and decide i don't want a parameter in certain situations. how would i bypass the prompt? i have gotten around this by using if/then statements but i'm thinking there is an easier way.
i tried explaining this question the best i could. but it still might be confusing. please let me know if you need more clarification on my question. thanks!
5 1801 ADezii 8,834
Recognized Expert Expert Howse about? -
If IsClosed("<Your Form Name Here>") Then
-
SELECT Tbl1.ID, Tbl1.[First Name], Tbl1.[Last Name] FROM Tbl1
-
Else
-
SELECT Tbl1.ID, Tbl1.[First Name], Tbl1.[Last Name]
-
FROM Tbl1
-
WHERE Tbl1.ID = [forms]![frmTest].[id];
-
End If
-
Function IsClosed(ByVal strFormName As String) As Boolean
-
'Returns True if the specified Form is closed , otherwise returns False
-
Const conObjStateClosed = 0
-
Dim intCounter As Integer
-
Dim blnFormExists As Boolean
-
-
blnFormExists = False 'initialize
-
-
'Let's see if the Form actually exists in the Database
-
For intCounter = 0 To CurrentDb.Containers("Forms").Documents.Count - 1
-
If CurrentDb.Containers("Forms").Documents(intCounter).Name = strFormName Then
-
blnFormExists = True
-
Exit For
-
End If
-
Next
-
-
If blnFormExists Then
-
'Form exists, but is it Closed?
-
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) = conObjStateClosed Then
-
IsClosed = True
-
Else
-
IsClosed = False
-
End If
-
Else
-
MsgBox "The Form (" & strFormName & ") does not exist in the Current Database", _
-
vbExclamation, "Form Does Not Exist"
-
End If
-
End Function
JKing 1,206
Recognized Expert Top Contributor
Out of curiousity what is the query being used for? By that I mean is the end result to display the query to a user? Or is it being used to supply data to a form or report?
The reason I ask is because that if you write a query that has no where clause to begin with you can add the where condition on the fly to filter your form/report. I'm not sure if it's what you are looking for but it is something to think about. This would also handle the situation where you want all data returned.
Howse about? -
Function IsClosed(ByVal strFormName As String) As Boolean
-
'Returns True if the specified Form is closed , otherwise returns False
-
Const conObjStateClosed = 0
-
Dim intCounter As Integer
-
Dim blnFormExists As Boolean
-
-
blnFormExists = False 'initialize
-
-
'Let's see if the Form actually exists in the Database
-
For intCounter = 0 To CurrentDb.Containers("Forms").Documents.Count - 1
-
If CurrentDb.Containers("Forms").Documents(intCounter).Name = strFormName Then
-
blnFormExists = True
-
Exit For
-
End If
-
Next
-
-
If blnFormExists Then
-
'Form exists, but is it Closed?
-
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) = conObjStateClosed Then
-
IsClosed = True
-
Else
-
IsClosed = False
-
End If
-
Else
-
MsgBox "The Form (" & strFormName & ") does not exist in the Current Database", _
-
vbExclamation, "Form Does Not Exist"
-
End If
-
End Function
wow, do u create code from scratch and post it on these forums? i admire your dedication to vba! that is a major upgrade over the code i created. i'm afraid to say that i was wondering if there was a way to bypass using a function like that. i was just curious if there was a simple command i could put in the criteria. for example, if i put the IS NULL command (idk if it's called a command, could be keyword.... whatever the technical name for it would be) in the criteria, it will return all the records that have null values for that field. the opposite goes for IS NOT NULL. it returns all the records that are not null. i was wondering if there was a command like (and i'm making this up) RETURN ALL and no criteria will be applied to that field in the where statement--which would return ALL records--no matter what the field contains. that way, i can fill the query parameter with "johnson" and it would return all records containing "johnson." but if i want to return all records, i could simply fill the query parameter with RETURN ALL. i don't know if a method of any sort exists for this or not but that's why i'm asking.
i just got to thinking that maybe to return all records, i would have to fill the parameter with IS NOT NULL OR IS NULL? i'm not sure how i would do that in the case of the querydefs example b/c it would be looking for a string and would simply return records that contain "is null or is not null" in the record.
i'm sorry i know i haven't describe this all that well. i've sat on this post for a while trying to figure out how to put into the best terms i can.
Out of curiousity what is the query being used for? By that I mean is the end result to display the query to a user? Or is it being used to supply data to a form or report?
The reason I ask is because that if you write a query that has no where clause to begin with you can add the where condition on the fly to filter your form/report. I'm not sure if it's what you are looking for but it is something to think about. This would also handle the situation where you want all data returned.
ok, i just created a new example. in the past, this is what i have done: -
-
If IsNull(Forms!StartEnd!FCFilter) = True Then
-
-
Set qdf = db.QueryDefs("qrySource4Email")
-
Set rs = qdf.OpenRecordset()
-
Else
-
Set qdf = db.QueryDefs("qrySource4EmailFiltered")
-
qdf.Parameters("[FCID]") = Forms!StartEnd!FCFilter
-
Set rs = qdf.OpenRecordset()
-
End If
i would rather simply have this line of code: -
-
Set qdf = db.QueryDefs("qrySource4EmailFiltered")
-
If IsNull(FCFilter) = False Then
-
qdf.Parameters("[FCID]") = Forms!StartEnd!FCFilter
-
Else
-
qdf.Parameters("[FCID]") = fill in blank 'i want this _
-
'to return all records... if i set it to "" it returns nothing
-
End If
-
Set rs = qdf.OpenRecordset()
this is a simple scenario of what i might run into. but there are many other instances besides this. hopefully this example paints a better picture?
oh my gosh i think i finally figured it out. i think the theoretical RETURN ALL statement i had been looking for is actually an asterisk! *
duh. i'd seen the asterisk used many times before but never put two and two together. well now i feel like an idiot lol.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: WGW |
last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost!
everything I need. Maybe not efficiently, but usefully. However, I have
a problem -- a complex query problem...
I can create a parameter query in a stored procedure, but how do I use
the result set of a parameter query in a select query (in the same or
another sp)? In short, if a select query contains a result table that is
generated as a parameter query, how do I...
|
by: Prashanth |
last post by:
Hi ,
I want to make a stored proc call thru .NET . I use the SqlParameter objects
to create input parameters and set it's value.
SqlParameter myParameter = new
SqlParameter("@Description",SqlDbType.VarChar);
myParameter.Value = "some string size not known. but max size of the string
can be only 1024 characters";
Note : I have not mentioned the size of the parameter using
|
by: Aguilar, James |
last post by:
Hey all. I was making a newbie mistake that I eventually figured out. That
is not my question. My question is about the error message. So let me set
the stage for you:
class Superclass
{
public:
Superclass(int);
}
|
by: thomas goodwin |
last post by:
I have a query which asks for a parameter value to execute it.
To see the results I have to:
a) click on the query -- the "Enter Parameter Value" window pops up.
b) enter the parameter value
c) look at results in datasheet view
If I want to run the query again, I must
d) click to close the datasheet view
e) click on the query
f) enter the parameter value
|
by: hecsan07 |
last post by:
I am writing some code that passes two parameters to a store procedure. One
of the parameters is an output parameter. I am querying the DB using the
input value and returning a field from the result using the output parameter.
The issue is that when I run the ExecuteNonquery command I get the following
error:
'@shortLinkUrl' of type: String, the property Size has an invalid size: 0
Any ideas? Please help. I am a beginner programmer...
| |
by: Britney |
last post by:
Original code:
this.oleDbSelectCommand1.CommandText = "SELECT TOP 100 user_id, password, nick_name, sex, age, has_picture, city, state, " +
"country FROM dbo.users WHERE (has_picture = ?) AND (sex = ?) ORDER BY age "
this.oleDbSelectCommand1.Parameters.Add(new System.Data.OleDb.OleDbParameter("has_picture", System.Data.OleDb.OleDbType.Boolean, 1, "has_picture"));
this.oleDbSelectCommand1.Parameters.Add(new...
|
by: Darwin Lalo |
last post by:
I have a lot of code like this:
VOID CALLBACK TimerRoutine(PVOID lpParam)
{
long nTaskid = (long)lpParam;
GObj *obj;
if( mapThreadSafe.find( nTaskid, obj )) // mapThreadSafe is a
hash_map, thread safe
{
|
by: hzmonte |
last post by:
Correct me if I am wrong, declaring formal parameters of functions as
const, if they should not be/is not changed, has 2 benefits;
1. It tells the program that calls this function that the parameter
will not be changed - so don't worry.
2. It tells the implementor and the maintainer of this function that
the parameter should not be changed inside the function. And it is for
this reason that some people advocate that it is a good idea to...
|
by: David Sanders |
last post by:
Hi,
I have a class with an integer template parameter, taking values 1, 2
or 3, and a function 'calc' in that class which performs
calculations. Some calculations need only be performed if the
template parameter is 2 or 3; for efficiency, I do not wish to perform
the calculations if the template parameter is 1.
I currently do this as follows:
|
by: HillBilly |
last post by:
One question I have not figured out is how to learn which event parameter
list is supported by a control? EventArgs, CommandEventArgs, what?
|
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...
| |
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: 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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: 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...
| |