473,748 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query parameters through a Form

418 Contributor
I have a Form where there are various combo boxes. These combo boxes are used as references for the parameter of various fields in a query. A command button opens a query with the parameters selected from the form.

I am having problem with two combo boxes which pulls data from the same table. These two combo boxes are called: txtActor and txtDirector. I am trying to generate a query to display any combination of actor and director (Or actor and actor) from the table called CAST.

I used these as a filter:
Expand|Select|Wrap|Line Numbers
  1. Like "*" & [Forms]![fReportList]![txtActor] & "*" Or Like "*" & [Forms]![fReportList]![txtDirector] & "*"
It does not work when I use AND in this filter. I need movies where Julia Roberts and Richard Gere acted together NOT Julia Roberts OR Richard Gere. Can someone please help? Thanks.
May 17 '10 #1
19 2198
NeoPa
32,571 Recognized Expert Moderator MVP
Simply change the Or you have, to an And :
Expand|Select|Wrap|Line Numbers
  1. [FieldName] Like '*' & [Forms]![fReportList]![txtActor] & '*'
  2. AND [FieldName] Like '*' & [Forms]![fReportList]![txtDirector] & '*'
PS. You also missed out the field you were comparing it to I noticed after posting (so I added that in too).

Are they the same field? it's not too clear from the question how your table is structured so it's hard to say exactly what is required to fit.
May 17 '10 #2
MNNovice
418 Contributor
@NeoPa
NeoPa:

Here is the SQL for my query. When I modify the second WHERE clause by replacing OR with AND, the qTest does not give me any data.

Expand|Select|Wrap|Line Numbers
  1. SELECT qitemsCast.iccID, [cFName] & "" & [cMName] & " " & [cLName] AS Name, qitemsCast.rName, qItems.iID, Type.tName, qItems.iNo, qItems.iTitle, Format.fAbbv, Language.lName, Category.cgName, qItems.Year, qItems.SubTitle, qItems.Color, qItems.Note
  2. FROM Type INNER JOIN ((((qItems INNER JOIN qitemsCast ON qItems.iID = qitemsCast.iciID) INNER JOIN Category ON qItems.cgID = Category.cgID) INNER JOIN Format ON qItems.fID = Format.fID) INNER JOIN [Language] ON qItems.lID = Language.lID) ON Type.tID = qItems.tID
  3. WHERE (((qitemsCast.iccID) Like [Forms]![fReportList]![txtActor] Or (qitemsCast.iccID) Like [Forms]![fReportList]![txtDirector]))
  4. ORDER BY [cFName] & "" & [cMName] & " " & [cLName];
  5.  
To answer your question, yes, it is the same field.

Here are the table structures:

1. Cast: cID (PK), cFName, cLastName
2. Items: iID (PK), iNo, iTitle,...
3. ItemsCast: icID (PK), iccID (FK for cID), iiID (FK for iID).

Table 1 and 2 are joined on each side of Table 3

Sample Report I would like: when two names are picked from two different combo boxes (txtActors and txtDirector) it will show all the titles avaialable for these two names. These combo boxes are based on the same table (CAST). If someone chooses Julia Roberts and Richard Gere the report should look like:

Titles with Julia Roberts and Richard Gere

1. Pretty Woman (iNo...)
2. Running Away Bride (iNo...)

Thanks.
May 17 '10 #3
MNNovice
418 Contributor
I solved my own problem. In the event someone else could find this helpful, here is what I did.

1. Created a query (qCast) filtering a form for the fields (txtActor) and (txtDirector).
2. Created a second query (qCast2) based on the frist query (qCast) restricting to no duplicate item.
3. Created a report based on qCast2. On top of the report page I added two text boxes to display the names selected on fReportList.

Thanks for all those who tried to help. Much appreciated.

Here are the SQL for qCast

Expand|Select|Wrap|Line Numbers
  1. SELECT qitemsCast.iciID, qitemsCast.iccID, [cFName] & "" & [cMName] & " " & [cLName] AS Name, qitemsCast.rName, qItems.iID, Type.tName, qItems.iNo, qItems.iTitle, Format.fAbbv, Language.lName, Category.cgName, qItems.Year, qItems.SubTitle, qItems.Color, qItems.Note
  2. FROM Type INNER JOIN ((((qItems INNER JOIN qitemsCast ON qItems.iID = qitemsCast.iciID) INNER JOIN Category ON qItems.cgID = Category.cgID) INNER JOIN Format ON qItems.fID = Format.fID) INNER JOIN [Language] ON qItems.lID = Language.lID) ON Type.tID = qItems.tID
  3. WHERE (((qitemsCast.iccID) Like '*' & [Forms]![fReportList]![txtActor] & '*' Or (qitemsCast.iccID) Like '*' & [Forms]![fReportList]![txtDirector] & '*') AND (([Forms]![fReportList]![txtDirector])<>False))
  4. ORDER BY [cFName] & "" & [cMName] & " " & [cLName];
  5.  
Here is the SQL for qCast2

Expand|Select|Wrap|Line Numbers
  1. SELECT qSelectCast.iID, qSelectCast.iNo, qSelectCast.tName, qSelectCast.iTitle, qSelectCast.fAbbv, qSelectCast.lName, qSelectCast.cgName, qSelectCast.Year, qSelectCast.SubTitle, qSelectCast.Color, qSelectCast.Note
  2. FROM qSelectCast
  3. WHERE (((qSelectCast.iID) In (SELECT [iID] FROM [qSelectCast] As Tmp GROUP BY [iID] HAVING Count(*)>1 )));
  4.  
May 17 '10 #4
NeoPa
32,571 Recognized Expert Moderator MVP
Mareena,

This is more complicated than it needs to be I'm sure. Your WHERE clause from earlier :
Expand|Select|Wrap|Line Numbers
  1. WHERE (((qitemsCast.iccID) Like [Forms]![fReportList]![txtActor] Or (qitemsCast.iccID) Like [Forms]![fReportList]![txtDirector]))
is trying to compare apples with pears! [iccID] looks like a numeric reference field, but the comparisons you're doing on it are textual. This cannot make sense.

Before you even start to look at the filtering of the query, you need to ensure the basics of your query are correct and return to you the data you need. An example of a field you will definitely need in your list, even just to do the filtering, would be something like [FullName]. I see you have one already called [Name]. You may have troubles using [Name] as a name, but we'll skip over that one for now.

Tip:
As a general rule, databases work better by separating out the elements of a name. Trying to search meaningfully on full names is fraught with complications.

How best to proceed really depends now on how you choose to organise your filtering. Name parts, or full names?
May 19 '10 #5
MNNovice
418 Contributor
@NeoPa
NeoPa:

I changed the expression "Name" to FullName. I would like to learn the reasons of not choosing [Name] as a field. If you can educate me on this issue, I will appreciate.

My goal is to get a list of items where two separate cIDs exist. What is the best way to do it?

1. I tried to do it through a combo box but a combo box does not allow more than one name (bound to cID)
2. If I change it to a List box - the form looks ugly with all those names...
3. So I created two separate combo boxes both tied to cID of table Cast.

Let me know my options if I were to list DVDs where both Julia Roberts and Richard Gere exist.

Thanks for taking the time to look into my problem.
May 25 '10 #6
NeoPa
32,571 Recognized Expert Moderator MVP
MNNovice: I changed the expression "Name" to FullName. I would like to learn the reasons of not choosing [Name] as a field. If you can educate me on this issue, I will appreciate.
I'll be happy to M.

Name, is a word that is already used to refer to properties of various objects in a database. IE Name already has a meaning, and when anyone sees it in code, their first assumption will be that is referring to something they understand. If one uses this to describe something else, then people will find it harder to understand what's going on and therefore errors are likely to occur.
MNNovice: My goal is to get a list of items where two separate cIDs exist. What is the best way to do it?
It's hard to say as I'm a little confused about what you have (though you've done a pretty decent job explaining).

What I would say is that txtActor & txtDirector indicate they are TextBox controls. If they are ComboBoxes instead then this changes a few things. The use of the word Like in the criteria can only be used for text fields. If these are IDs then that will not work.
May 26 '10 #7
MNNovice
418 Contributor
@NeoPa
NeoPa:
Thanks for the detailed explanations on "Name".

Let me explain my goal:

Table Cast has 4 fields
1. cID (PK)
2. cFName
3. cMName
4. cLName

Table Items is the main table
1. iID (PK)
2. iTitle (Title of a DVD eg.)
3. iNo (Serial Number)
4. A few more text fields like cgID (category), lID (Language) etc.

ItemCast table
1. icID (PK)
2. iccID (to conenct to Cast)
3. iciID (to connect to Items)

Form fReportList

I created two separate combo boxes (even though I named them txtActors and txtDirectors: it should have been cboActors...)

My goal is to create a report that will list all DVDs where two different actors, for example, have acted together. If I were to list all movies Clint Eastwood directed where Ed Harris is an actor. How do I do this combo cIDs (it can be any combinations)?

Hope this explains it better.

Thanks again. M
May 26 '10 #8
NeoPa
32,571 Recognized Expert Moderator MVP
To start with let me just confirm that ComboBoxes returning ID values cannot be used with the Like operator. The Like operator is exclusively a string matching operator.

I suggest this means you are trying to filter records where cast members include both your [cboActor] value and your [cboDirector] value?

From my reading of this the director of the film is listed as simply another member of the cast. Is that correct?
May 27 '10 #9
MNNovice
418 Contributor
I suggest this means you are trying to filter records where cast members include both your [cboActor] value and your [cboDirector] value?
Yes.


From my reading of this the director of the film is listed as simply another member of the cast. Is that correct?
Yes. For actors and directors I didn't create separate tables instead created a single table called Cast. This way I didn't have to make changes in two different tables.

If my questions don't make sense and get confusing, please let me know. I will be happy to post a copy of my DB.
May 27 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4164
by: William Wisnieski | last post by:
Hello Everyone Access 2000 Looking for some suggestions and advice on how to proceed with this. I hope its not as complicated as it seems to me right now. I've got an unbound main form with a subform bound to a query . What I'd like to do is have the user choose criteria from four objects on the main form then click a button that displays the
1
2914
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access 2000. The access file is in access 2000 format. I have a form that will hold the relevent parameters for the query/report that reports the statistics for all job records that match a certain criteria. These are: - A Customer Name.
4
2607
by: RBohannon | last post by:
I'm using Access 2000. I currently have a report being generated using the results of a query by form. The form used for this query is an unbound form, frmListDialog. frmListDialog contains two unbound text boxes, txtExamTitle and txtExamNumber. The user enters either the exam title in txtExamTitle or the exam number in txtExamNumber as a parameter for the query. This is currently working fine, however because the exam titles are...
5
2360
by: ric_deez | last post by:
Hi there, I would like to create a simple search form to allow users to search for a job number based on a number of parameters. I think I understand how to use parameteres associated with Stored Procedures with a data reader to add various parameters. However, if I have a stored procedure such as CREATE usp_SelectfromJobNumbers (@par1 datatype, @par2 datatype, @par3 datatype)
4
5515
by: amorphous999 | last post by:
I am running Access 2002. I have some reports I would like to be able to run from VBA or interactively. The reports use queries with parameters. When the user runs the report, the parameter prompts for the query are displayed, and the user fills them in. What I would like to do is set those parameter values from VBA when running the reports. Is there a way to do that? Thanks in advance, amorphous
6
5259
by: ljungers | last post by:
Hi to all and hope someone may have an answer for me. I have a Form named Cust_lukup_Form that has 3 text boxes and a click button that uses a OnClick to call Cust_lukup_Macro that runs an OpenQuery named Cust_lukup_Query using the text box(s) input data running in print view mode. The Cust_lukup_Query has the code setup to query the 3 fields using 1, 2 or 3 of the boxes or selecting all if there blank. What I need to do is add another...
6
1703
by: sunil | last post by:
I have a button named Button1, and I wrote an event handler for the OnClick event. protected void Button1_Click(object sender, System.EventArgs e) { this.Response.Redirect("Default.aspx?q=" + this.TextBox1.Text+ " "); } The TextBox1 is a text box that takes user input. I get the text box content by extracting the query parameters as
5
5306
by: dana1 | last post by:
Hello Experts! Does anyone know if there is a way to set the values of query parameters from VBA for a report's recordsource? (i.e., I want to set the values of the parameters and NOT have the user prompted for them). Based on a Microsoft page (http://support.microsoft.com/kb/287437), I tried the following approach: Private Sub Report_Open(Cancel As Integer) Dim sql As String
17
2733
by: NeoAlchemy | last post by:
I am starting to find more web pages that are using a query parameters after the JavaScript file. Example can be found at www.opensourcefood.com. Within the source you'll see: <script src="/shared/scripts/common.js?revision=1.6" type="text/javascript">. I am trying to see if there is any big deal to this or a best practice that is starting to creep up in the JavaScript community. If this is used only as a way to distinguish what...
2
1683
by: raaman rai | last post by:
i have 3 drop dropdown box which is used for searching my database. Either one of them can be selected to perform the search but if none of them is selected it will give an error. Well in reference to this i want the sql query to be based on the values selected by the users. A user might select value from one dropdown box and leave the others or a user can also select values from all three dropdown box. So in this case the query parameters for...
0
8994
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
9555
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
9376
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 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...
0
9250
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
8247
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...
1
6796
isladogs
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...
0
4607
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...
0
4878
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
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

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.