473,385 Members | 1,492 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,385 software developers and data experts.

Query parameters through a Form

418 256MB
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

✓ answered by NeoPa

Change the HAVING clause to :
Expand|Select|Wrap|Line Numbers
  1. HAVING   (Min(iccID)<Max(iccID))
That leaves the SQL as :
Expand|Select|Wrap|Line Numbers
  1. SELECT   [iciID]
  2.  
  3. FROM     [ItemCast]
  4.  
  5. WHERE    (iccID In(Forms.fReportList.cboDirector
  6.                   ,Forms.fReportList.cboActor))
  7.  
  8. GROUP BY [iciID]
  9.  
  10. HAVING   (Min(iccID)<Max(iccID))

19 2165
NeoPa
32,556 Expert Mod 16PB
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 256MB
@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 256MB
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,556 Expert Mod 16PB
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 256MB
@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,556 Expert Mod 16PB
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 256MB
@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,556 Expert Mod 16PB
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 256MB
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
NeoPa
32,556 Expert Mod 16PB
Thank you M. That probably won't be necessary for now, though I don't have time to work out the solution just now. I think I have what I need to work on so plan to do one later.
May 27 '10 #11
MNNovice
418 256MB
@NeoPa
NeoPa:

Thanks for your prompt response. I appreciate your help.

I wait for your next response. Have a good day. M
May 27 '10 #12
NeoPa
32,556 Expert Mod 16PB
Try this M :
Expand|Select|Wrap|Line Numbers
  1. SELECT   [iciID]
  2.  
  3. FROM     [ItemCast]
  4.  
  5. WHERE    (iccID In(Forms.fReportList.cboDirector
  6.                   ,Forms.fReportList.cboActor))
  7.  
  8. GROUP BY [iciID]
  9.  
  10. HAVING   (Count(*)>1)
May 27 '10 #13
MNNovice
418 256MB
NeoPa:

I think we are almost there. It's working BUT it adds to the list with items that does not belong to the combination I select. For example, if the selected director is also an actor or a music director of a movie where the selected actor is absent - the list includes the item in addition to where both the selected actor director are present. Am I explaining the problem?

Suppose I selected Clint Eastwood (director) and Laura Linney(actor) and suppose there are 2 common items where these two casts exist. Your code produces a query which shows 4 more items where Laura Linney is NOT an actor but Clint Eastwood is a producer or an actor...


Hummmm! what to do now?
May 27 '10 #14
NeoPa
32,556 Expert Mod 16PB
Change the HAVING clause to :
Expand|Select|Wrap|Line Numbers
  1. HAVING   (Min(iccID)<Max(iccID))
That leaves the SQL as :
Expand|Select|Wrap|Line Numbers
  1. SELECT   [iciID]
  2.  
  3. FROM     [ItemCast]
  4.  
  5. WHERE    (iccID In(Forms.fReportList.cboDirector
  6.                   ,Forms.fReportList.cboActor))
  7.  
  8. GROUP BY [iciID]
  9.  
  10. HAVING   (Min(iccID)<Max(iccID))
May 27 '10 #15
MNNovice
418 256MB
@NeoPa
NeoPa:

Yeahhhhhhhhhh! Simply put you are a genius. What can I say? Awsome. Thank you very much.

Now will you have time to spare and look at this posting I have? Please see my comments on #18

Prevent entering duplicate value

Thanks again.
May 27 '10 #16
NeoPa
32,556 Expert Mod 16PB
I'll look if I can M. Currently the link isn't working so I'll have a look via your profile page for recently posted threads.
May 27 '10 #17
MNNovice
418 256MB
@NeoPa
Thanks so much. I really appreciate.
May 27 '10 #18
MNNovice
418 256MB
I wanted to mark answer in posting #15 as the "best answer" but somehow lost the click button to do so. Hope one of you Guru's will help me reset this answer as the BEST. thanks.

NeoPa, Thank you.
May 27 '10 #19
NeoPa
32,556 Expert Mod 16PB
I more than helped you M. I set it (Post #15) myself for you 3 or 4 hours beforehand.

I often set the Best Answer for threads in my moderator role.
May 27 '10 #20

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

Similar topics

2
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...
1
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...
4
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...
5
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...
4
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...
6
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...
6
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=" +...
5
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...
17
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...
2
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.