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
RecordingID
RecordingTitle
ArtistID
ArtistName
Main Form 1: frmFIND
Text box 1 = txtCDTitle (Unbound)
Combo Box 1 = cboArtist (Unbound) but has this code under Row Source -
-
SELECT 0 as ArtistID, "<ALL>" as ArtitstName FROM tblzNull UNION ALL SELECT tblArtists.ArtistID, tblArtists.ArtistName FROM tblArtists
-
ORDER BYArtistName;
-
-
Sub Form 1 - sfrmCD
RecordingID
RecordingTitle
ArtistName
Command Button 1: cmdFIND -
-
Private Sub cmdFIND_Click()
-
' Update the record source
-
Me.sfrmCD.Form.RecordSource = "SELECT * FROM qryCD " & BuildFilter
-
-
' Requery the subform
-
Me.sfrmCD.Requery
-
End Sub
-
-
Private Sub Form_Load()
-
-
' Clear the search form
-
cmdCLEAR_Click
-
-
End Sub
-
-
Private Function BuildFilter() As Variant
-
Dim varWhere As Variant
-
Dim varItem As Variant
-
Dim intIndex As Integer
-
-
varWhere = Null ' Main filter
-
-
-
' Check for LIKE CD Title
-
If Me.txtCDTitle > "" Then
-
varWhere = varWhere & "[RecordingTitle] LIKE """ & Me.txtCDTitle & "*"" AND "
-
End If
-
-
' Check for ArtistID
-
If Me.cboArtist > 0 Then
-
varWhere = varWhere & "[ArtistName] = " & Me.cboArtist & " AND "
-
End If
-
-
-
' Check if there is a filter to return...
-
If IsNull(varWhere) Then
-
varWhere = ""
-
Else
-
varWhere = "WHERE " & varWhere
-
-
' strip off last "AND" in the filter
-
If Right(varWhere, 5) = " AND " Then
-
varWhere = Left(varWhere, Len(varWhere) - 5)
-
End If
-
End If
-
-
BuildFilter = varWhere
-
-
End Function
-
-
Sorry for the long note. But felt that details may help you understand my problem better. Many thanks.
10 2591 NeoPa 32,586
Recognized Expert Moderator MVP
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!
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: - SELECT 0 as ArtistID,
-
"<ALL>" as ArtitstName
-
-
FROM tblzNull
-
-
UNION ALL SELECT ArtistID,
-
ArtistName
-
-
FROM tblArtists
-
-
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 - SELECT 0 as ArtistID,
-
"<ALL>" as ArtitstName
-
-
FROM tblzNull
-
-
UNION ALL SELECT ArtistID,
-
ArtistName
-
-
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
END DEBUG
I chose DEBUG which takes me to the VBA page and Line 3 (below) is highlighted in yellow. - Private Sub cmdFIND_Click()
-
' Update the record source
-
Me.sfrmCD.Form.RecordSource = "SELECT * FROM qryCD " & BuildFilter
-
-
' Requery the subform
-
Me.sfrmCD.Requery
-
End Sub
PLEASE HELP. Is it possible to attach a smaller version of my Database here?
I appreciate your time. Thanks.
NeoPa 32,586
Recognized Expert Moderator MVP
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).
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.
NeoPa 32,586
Recognized Expert Moderator MVP
To get this, simply, when you have selected DEBUG, do the following : - Type Ctrl-G to open and select the Immediate Pane
- Type in ?BuildFilter
- 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.
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: - ' Check for RecordingArtistID
-
If Me.cboArtist > 0 Then
-
varWhere = varWhere & "[RecordingArtistName] = '" & Me.cboArtist.Column(1) & "' AND "
-
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.
NeoPa 32,586
Recognized Expert Moderator MVP
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.
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.
NeoPa 32,586
Recognized Expert Moderator MVP
So where is this other problem explained? If you drop in a link I will have a look.
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 data from several
tables into the form and i would like to eventually be able to filter
down through the
tables untill i can reach one unique record. I am creating a datbase
to keep track of registered accounts for a stae program. Each
account is registered into the program through a two...
|
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
and this requeries a sub query in the form and displays data dependent
on what has been typed in.
After having trouble with populating my second combo box (I eventually
populated it by putting the fields for both combo boxes in 1 separate
query) I am now having problems with the 3rd one and am...
|
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 combo 1
restricts the options available in combo 2.
The row source for combo2 is:
SELECT DISTINCT tblComplaintCategory.fldComplaintCategory,
tblComplaintCategory.fldComplaintCategoryID,
tblComplaintSubjects.fldComplaintSubjectID
|
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 is primary key (ID). Second column is a concatenation of
two fields (Descrip & UserID).
When I start typing letters of an existing description (Descrip), the
combo does not autocomplete. If I select a choice from the combo, it
|
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 your help already,
Dave
| |
by: buddyr |
last post by:
Hello,
I am having trouble with two combo boxes working together.
two tables table1 table2
table1 fields -number and name
table 2 fields -code and number
data in table one field number 1,2,3
data in table one field name Tom, Bob, Jim
data in table two field code 11,22,33,44,55,66,
data in table two field number 1,2,3,1,2,3
|
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 what is selected on the first dropdown the second one gets populated accordingly, which is great! There are two problems;
First the when I select the value from the second drop down the value in the first and second combo box go away!!
Second when I remove the filter the values for all the...
|
by: kcdoell |
last post by:
I have three tables:
One for the Division location:
tblDivision
DivisionID = Autonumber
DivisionName = Text
One for the Working Region:
tblWrkRegion
|
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. My task is simple, but I'm having a hard time working it out.
Once an option is selected in the combo box, I want to run (a macro?)
that will grab the appropriate default notes from the table, and load
them into the form in the various Notes fields.
I've got a query set up that'll narrow the...
|
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 main form. Now I'm trying to do it on a datasheet subform and it is not working. After making the selection in the first combo box, when I move to the second combo box, I get the Access input parameters box. If I input the value that is in the first combo box, I get the expected results in the second...
|
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: 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: 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: 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: 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: 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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |