Hello
Just a quick question that I've spent a few hours trying to solve with
no luck (although one would think this should be fairly easy).
I have a form with a subform. The subform is based on a query. The
criteria for the query is based on the user's input in the main form.
One of the user inputs is a field called "Vendor_Nam e" (in the form of
a combo box). I would like the query to run for all "Vendor_Nam e" if
the user leaves the field blank. However, if the user selects a
"Vendor_Nam e", then I would like the query to run with the selected
criteria.
I've tried an "IIF" statement in the query criteria with no luck, also
tried (my best) to write VB code to do the same, again without any
luck.
I'm sure there is a simple solution, but I have yet to find it. Any
help at all would be appreciated.
Best,
Kelii 7 3789
> I have a form with a subform. The subform is based on a query. The criteria for the query is based on the user's input in the main form. One of the user inputs is a field called "Vendor_Nam e" (in the form of a combo box). I would like the query to run for all "Vendor_Nam e" if the user leaves the field blank. However, if the user selects a "Vendor_Nam e", then I would like the query to run with the selected criteria.
I suggest you to change the SELECT used for RowSource of the combo in the
main form.
Said the SELECT statement is similar to
SELECT Filed1, Field2, ...., FieldN FROM MyTable
and said that Field1 is the primary key and is an autonumber field, and Field2
is the field shown in the combo box, you must modify it to a UNION select,
similar to
SELECT Field1, Field2, ...., FieldN FROM MyTable
UNION 0 AS Field1, '<all>' AS Field2, NULL AS Field3, ...., NULL AS FieldN
FROM MyTable
then, you should change the SELECT used for RecordSource of the subform.
Said this SELECT is similar to
SELECT Field1, Field2, ...., FieldX FROM MyTable
you must modify it in a way similar to
SELECT Field1, Field2, ...., FieldX FROM MyTable
WHERE (Field1 = [Forms]![nameofthemainfo rm]![nameofthecombob ox]) OR
([Forms]![nameofthemainfo rm]![nameofthecombob ox] = 0)
Bye.
--
PBsoft di Gabriele Bertolucci www.pbsoft.it
skype: pbsoftsolution
Open your underlying query in design-grid view and something like below:
Like IIf([Forms]![frmMyForm]![pickCombBox] Is
Null,"*",[forms]![frmMyForm]![pickCombBox])
as the criteria in the column of your main form combobox.
-Ed
<ke****@yahoo.c om> wrote in message
news:11******** *************@j 52g2000cwj.goog legroups.com... Hello
Just a quick question that I've spent a few hours trying to solve with no luck (although one would think this should be fairly easy).
I have a form with a subform. The subform is based on a query. The criteria for the query is based on the user's input in the main form. One of the user inputs is a field called "Vendor_Nam e" (in the form of a combo box). I would like the query to run for all "Vendor_Nam e" if the user leaves the field blank. However, if the user selects a "Vendor_Nam e", then I would like the query to run with the selected criteria.
I've tried an "IIF" statement in the query criteria with no luck, also tried (my best) to write VB code to do the same, again without any luck.
I'm sure there is a simple solution, but I have yet to find it. Any help at all would be appreciated.
Best,
Kelii
Ed - thanks for the response, it didn't seem to work.
This is the text that I put into the query criteria:
Like IIf([Forms]![frmInvoiceLooku p]![Vendor_Name] Is
Null,"*",[Forms]![frmInvoiceLooku p]![Vendor_Name])
Here is the full query:
SELECT tblInvoiceMaste r.Invoice_ID, tblInvoiceMaste r.Company_Locat ion,
tblInvoiceMaste r.Invoice_Date, tblInvoiceMaste r.Invoice_Numbe r,
tblInvoiceMaste r.Vendor_Name, tblInvoiceMaste r.Total_Invoice _Amount
FROM tblInvoiceMaste r GROUP BY tblInvoiceMaste r.Invoice_ID,
tblInvoiceMaste r.Company_Locat ion, tblInvoiceMaste r.Invoice_Date,
tblInvoiceMaste r.Invoice_Numbe r, tblInvoiceMaste r.Vendor_Name,
tblInvoiceMaste r.Total_Invoice _Amount HAVING
(((tblInvoiceMa ster.Company_Lo cation)=[Forms]![frmInvoiceLooku p]![Company_Locatio n])
AND
((tblInvoiceMas ter.Invoice_Dat e)>=[Forms]![frmInvoiceLooku p]![Invoice_Begin_D ate]
And
(tblInvoiceMast er.Invoice_Date )<=[Forms]![frmInvoiceLooku p]![Invoice_End_Dat e])
AND ((tblInvoiceMas ter.Vendor_Name ) Like
IIf([Forms]![frmInvoiceLooku p]![Vendor_Name] Is
Null,"*",[Forms]![frmInvoiceLooku p]![Vendor_Name])));
Any other thoughts?
Best,
Kelii
Hello Kel,
With the risk of sounding redundant, the expression below
is basically what I use to deal with the problem your having
and works for me everytime.
Perhaps you can give it a go! I use the build button to get
the correct path I need to the control on the main form for
the field in the query.
Result:
Forms![MainFormName]![FieldNameOnForm] 0r
Forms![MainFormName]![FieldNameOnForm] Is Null
Just get the path to the control you need and then repeat
it again after an "or" with the "Is Null" at the end.
This way, it looks to see if there is data in the field first,
then if it is null, you get all records.
Regards
It looks OK; try deleting all the other criteria from your query and test
if the response works then. This assume that ALL records have value in
[Vendor_Name]; if not you'll have to add "or is Null" to that particular
query criteria.
-Ed
<ke****@yahoo.c om> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.com.. . Ed - thanks for the response, it didn't seem to work.
This is the text that I put into the query criteria: Like IIf([Forms]![frmInvoiceLooku p]![Vendor_Name] Is Null,"*",[Forms]![frmInvoiceLooku p]![Vendor_Name])
Here is the full query: SELECT tblInvoiceMaste r.Invoice_ID, tblInvoiceMaste r.Company_Locat ion, tblInvoiceMaste r.Invoice_Date, tblInvoiceMaste r.Invoice_Numbe r, tblInvoiceMaste r.Vendor_Name, tblInvoiceMaste r.Total_Invoice _Amount FROM tblInvoiceMaste r GROUP BY tblInvoiceMaste r.Invoice_ID, tblInvoiceMaste r.Company_Locat ion, tblInvoiceMaste r.Invoice_Date, tblInvoiceMaste r.Invoice_Numbe r, tblInvoiceMaste r.Vendor_Name, tblInvoiceMaste r.Total_Invoice _Amount HAVING (((tblInvoiceMa ster.Company_Lo cation)=[Forms]![frmInvoiceLooku p]![Company_Locatio n]) AND ((tblInvoiceMas ter.Invoice_Dat e)>=[Forms]![frmInvoiceLooku p]![Invoice_Begin_D ate] And (tblInvoiceMast er.Invoice_Date )<=[Forms]![frmInvoiceLooku p]![Invoice_End_Dat e]) AND ((tblInvoiceMas ter.Vendor_Name ) Like IIf([Forms]![frmInvoiceLooku p]![Vendor_Name] Is Null,"*",[Forms]![frmInvoiceLooku p]![Vendor_Name])));
Any other thoughts?
Best,
Kelii
Inkman,
Thanks for the response, your suggestion works for 99% of the issue,
which I'm willing to live with. The only complication is that the "Is
Null" criteria seems to prevent the other query criteria from
functioning properly; e.g., the date criteria have no effect when I
leave the Vendor_Name criteria blank. I've repeated the date query
criteria in the second row of the query criteria along with the "Is
Null" for Vendor_Name, but still no luck.
I'll keep playing with it to see if it works, however, great
suggestions and thanks for the help.
Best,
Kelii
Inkman,
Scratch earlier comment, your suggestion works perfectly.
Thanks again,
Kelii This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steve |
last post by:
I am using Access 2000 and I have a DB that is currently running four
different queries from some Forms and subforms. These queries each
have a date field that are seperate from each other that are from
those said forms. Currently I have setup the criteria for these
queries to prompt a user to enter a month #
Query Field: Month()
Criteria:
|
by: waynetheengineer |
last post by:
Hi,
I was wondering if anyone had any suggestions on my database:
I have a form that accepts user input into a single text box. When the OK button is hit, a query should search for all records that contain the user inputted text for a specific field in the query's criteria section. I want the criteria to search for any matching part of the word, for example:
If the user enters in the text box: rabbit
The query should return all...
|
by: ericargent |
last post by:
Hi
I'm using Acces 2003
I have Query where the several parameters for the criteria are supplied from a form. One parameter source is a combo box. What I am trying to do is if:
An item is selected on the combo box then that value is used as the criteria
If user does not want the contents of the combo box used, then Query should ignore that field.
I have tried to do this with an iif statement in the query criteria and a control box on...
|
by: sfrvn |
last post by:
I have searched high and low and cannot find an answer to my problem.
So now I turn to the collective genius of this newsgroup.
Over-simplified examples
This query criteria for field works:
IIf(1=1,#3/12/2007#,#3/12/2007#)
1=1 will be replaced by actual 'test'; I just want to make sure
expression evaluates 'true'
Query returns all records where field equals
3/12/2007date
|
by: cmartin1986 |
last post by:
First of all I want to thank all of you that have helped me in the past this is an awesome fourm.
My problem today is I have a database that builds charts that are viewed by a large group every friday morning. I am building six different charts that all have query criteria of between two dates right now I am going and updating the charts manually every week. The dates these charts work on is always friday to thursday every week. Is there...
| |
by: tbeers |
last post by:
Is there a method to pass along a criteria argument directly to the query criteria rather than through filtering a form or report?
In other words, I would like to click a "print" button and in the "on click" procedure pass along the criteria to the query to generate this report. Then I wouldn't have to create so mahy different queries. I know that I can take a control value to use in the criteria box in the query. But I would like to be...
|
by: limperger |
last post by:
Hello everyone!
First and foremost, my apologies for the title of the post. It is not very clarifying of what the problem is about, but I didn't know how to put it...
My problem is as follows: I have a parameter query consisting of 2 fields (month and year). The parameter prompts the user to enter the month and the year, that is, . When both are entered, there is no problem. Nevertheless, users may want only to enter the year, so as to...
|
by: sharsy |
last post by:
Hello guys,
I would like some help in generating query criteria that will identify
credit cards that have expired on an access database.
The specific Field is formatted with a Data Type of
'Text' and has an input mask of '00/00', so all expiry dates are set
out for example as 10/13 (which represents October 2013).
I have hada brief go at trying to work it out, but I was unable to
|
by: ajhayes |
last post by:
Hello everyone,
This is my first time posting here and I'm hoping someone can help me out. I'm a relative newbie to Access and am pretty much learning as I go along, so please bear with me.
Here is what I am trying to do. I'm building a simple database that will allow our engineering staff to enter in the items from the inventory warehouse that will be required for a project. Each inventory item has a unique part number, which is...
|
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: 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,...
| |
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |