472,353 Members | 1,292 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Combo Box not working

418 256MB
Hello all:

I could not get a combo box to display a list in a Search Form. My object is to select an artist's name and have his/her CDs listed on the subform through a qry. But I couldn't do it. When I tried to type an artist's name, I get an error message telling me the name does not exist in the list. I was successful in getting data by typing a CD title but couldn't get the Combo box for the Artist's search to work. Can someone please help?

Details follow:

Table 1: tblArtists
ArtistID - Auto (PK)
ArtistName- Text

Table2: tblCDDetails
RecordID - Auto (PK)
RecordingTitle - Text
ArtistID - FK

Table 3: tblzNull
ItemID - Auto (PK)
ItemName - Text

Query 1: qryCD

Main Form 1: frmFIND
Text box 1 = txtCDTitle (Unbound)
Combo Box 1 = cboArtist (Unbound) but has this code under Row Source

Expand|Select|Wrap|Line Numbers
  2. SELECT 0 as ArtistID, "<ALL>" as ArtitstName FROM tblzNull UNION ALL SELECT tblArtists.ArtistID, tblArtists.ArtistName FROM tblArtists
  3. ORDER BYArtistName;
Sub Form 1 - sfrmCD

Command Button 1: cmdFIND

Expand|Select|Wrap|Line Numbers
  2. Private Sub cmdFIND_Click()
  3.   ' Update the record source
  4.     Me.sfrmCD.Form.RecordSource = "SELECT * FROM qryCD " & BuildFilter
  6.     ' Requery the subform
  7.     Me.sfrmCD.Requery
  8. End Sub
  10. Private Sub Form_Load()
  12.     ' Clear the search form
  13.     cmdCLEAR_Click
  15. End Sub
  17. Private Function BuildFilter() As Variant
  18.     Dim varWhere As Variant
  19.     Dim varItem As Variant
  20.     Dim intIndex As Integer
  22.     varWhere = Null  ' Main filter
  25.     ' Check for LIKE CD Title
  26.     If Me.txtCDTitle > "" Then
  27.         varWhere = varWhere & "[RecordingTitle] LIKE """ & Me.txtCDTitle & "*"" AND "
  28.     End If
  30.     ' Check for ArtistID
  31.     If Me.cboArtist > 0 Then
  32.         varWhere = varWhere & "[ArtistName] = " & Me.cboArtist & " AND "
  33.     End If
  36.     ' Check if there is a filter to return...
  37.     If IsNull(varWhere) Then
  38.         varWhere = ""
  39.     Else
  40.         varWhere = "WHERE " & varWhere
  42.         ' strip off last "AND" in the filter
  43.         If Right(varWhere, 5) = " AND " Then
  44.             varWhere = Left(varWhere, Len(varWhere) - 5)
  45.         End If
  46.     End If
  48.     BuildFilter = varWhere
  50. End Function
Sorry for the long note. But felt that details may help you understand my problem better. Many thanks.
Aug 28 '08 #1
10 2457
32,511 Expert Mod 16PB
Have a look at Example Filtering on a Form and see if you can do it after that.

If not, please come back and let us know in here. We will expect you to be familiar with what's in that thread though.

Welcome to Bytes!
Aug 28 '08 #2
418 256MB
I read the instructions you sent CH 1 -7 plus the article by RABBIT. Thanks.

I still need help.

My Combo Box on the main form is called cboArtist

Column Count = 2
Bound Column = 1

Control Source = Unbound
Row Source Type = Table/Query
Row Source:
Expand|Select|Wrap|Line Numbers
  1. SELECT 0 as ArtistID,
  2.        "<ALL>" as ArtitstName
  4. FROM tblzNull
  7.                  ArtistName
  9. FROM tblArtists
  11. ORDER BY ArtistName;
It does not display any Artistís name. When I try to execute the FIND button, I get this error message:

The ORDER BY expression (ArtistName) includes fields that are not selected by the query. Only those fields requested in the first query can be included in an ORDER BY expression.

I am not at all GOOD with SQL commands and am learning as I go. My query name is qryCD lists ArtistName to be sorted. Why do I get this message then?

So I edited the SQL to read it as
Expand|Select|Wrap|Line Numbers
  1. SELECT 0 as ArtistID,
  2.        "<ALL>" as ArtitstName
  4. FROM tblzNull
  7.                  ArtistName
  9. FROM tblArtists;
This allows me to see the list of Artistsí Names. But when I select one name and Click on FIND button I get this weird error message which I donít understand at all.

Run-Time Error Ď2001í:
You canceled the previous operation

I chose DEBUG which takes me to the VBA page and Line 3 (below) is highlighted in yellow.
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFIND_Click()
  2.   ' Update the record source
  3.   Me.sfrmCD.Form.RecordSource = "SELECT * FROM qryCD " & BuildFilter
  5.   ' Requery the subform
  6.   Me.sfrmCD.Requery
  7. End Sub
PLEASE HELP. Is it possible to attach a smaller version of my Database here?

I appreciate your time. Thanks.
Aug 28 '08 #3
32,511 Expert Mod 16PB
I took the liberty, while I was editing your post to include the [ CODE ] tags, of reformatting your SQL code too (just for visual display - not to change the effect).

You will notice more easily now that the field [ArtitstName] on line #2 of each is misspelled.

In a UNION query, the field name is ALWAYS determined by the first query, so the subsequent query that's UNIONed with it, doesn't matter - even though it is spelt correctly there.

For your code breaking (at line #3 shown) I can't help too much as most of the information is not available to me. I have no info about qryCD or BuildFilter.

What I can say though, is that rather than changing the .RecordSource, it's probably easier simply to set the .Filter itself and call a .ReQuery. The .ReQuery you have on line #6 seems wrong to me too. It is the form that needs to be requeried and not the subform control (which can contain a subform).
Expand|Select|Wrap|Line Numbers
  1. Me.sfrmCD.Form.Requery
As to attaching a database, it is possible, but personally I would not do it unless requested. I see it as shorthand for "I don't want to go to the effort of explaining my problem clearly. I'd prefer if you spent you time trying to work it out instead".

Some experts do request it and that's absolutely fine, but if not requested then it's better not to in my view.
Aug 28 '08 #4
32,511 Expert Mod 16PB
To get this, simply, when you have selected DEBUG, do the following :
  1. Type Ctrl-G to open and select the Immediate Pane
  2. Type in ?BuildFilter
  3. Copy the results displayed in with your next post
It may be clear and simple from whatever it displays, but we may need to know a bit more about [qryCD] if it's not.
Aug 28 '08 #5
418 256MB
Thank you for taking the time to explain things to me. I sincerely appreciate. I am happy to report that I was able to fix this problem. All I needed is to add the column number to the SQL under ArtistID. In the event someone else could benefit from it, here is the revised code:
Expand|Select|Wrap|Line Numbers
  1. ' Check for RecordingArtistID
  2.     If Me.cboArtist > 0 Then
  3.         varWhere = varWhere & "[RecordingArtistName] = '" & Me.cboArtist.Column(1) & "' AND "
  4.     End If
Many thanks for your help. I am still struggling with the problem of creating a text box to automatically populate with running numbers.
Aug 30 '08 #6
32,511 Expert Mod 16PB
Thank you for posting your answer. That always helps.

I'm not sure from your last what, if anything, you still want help with.

If there is still something you need perhaps you could explain it again to save me trying to determine by rereading everything from scratch.
Aug 30 '08 #7
418 256MB
Thank you and my apologies for not being clear.

I was able to solve the problem that you tried to help. I was referring to another problem I am still struggling with.
Sep 2 '08 #8
32,511 Expert Mod 16PB
So where is this other problem explained? If you drop in a link I will have a look.
Sep 2 '08 #9
418 256MB
Here is the link.

1. Please help with Running Count
Sep 3 '08 #10
32,511 Expert Mod 16PB
It looks complicated, but I'll have a longer look sometime and see if I can decipher it.
Sep 3 '08 #11

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

Similar topics

by: Sean | last post by:
Greetings all, I am attempting to make a form that will filter through several tables that (I believe) have refretial integrity. I am pulling...
by: visionstate | last post by:
Hi there, I am working on a form that uses 3 text boxes and 3 combo boxes. When any data is entered into any of these, I click a command button...
by: consonanza | last post by:
I am working on a report filter form. It has 2 combo boxes (cmboSelectSubject and cmboSelectCategory) to select criteria. Selecting an entry in...
by: John | last post by:
AC2007 I changed my combo's row source and then the autocomplete stopped working. The combo is two columns, bound to the first. First column...
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for...
by: buddyr | last post by:
Hello, I am having trouble with two combo boxes working together. two tables table1 table2 table1 fields...
by: Dev1 | last post by:
All- I'm new to this forum and i've been working with acces for about 2 days now. I have a form in which I have two combo boxes and depending on...
by: kcdoell | last post by:
I have three tables: One for the Division location: tblDivision DivisionID = Autonumber DivisionName = Text One for the Working Region:...
by: Tim | last post by:
I'm working on a form where a combo box gets its list of values from a table. That same table also contains some "default notes" in other fields....
by: WyvsEyeView | last post by:
I am doing the very standard thing of filtering the contents of one combo box based on another combo box. I've done it many times, but always on a...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.