473,756 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

listbox rowsource query problem

I'm trying to design a database to track projects and the associates
assigned to them. I have almost no experience with this. I have three
tables:
-Projects
-Associates
-Assignments
where assignments contains projectID and associateID and is related to
the projects.projec tID primary key and the associates.asso ciateID
primary key. I have a form based on the projects table that contains a
list box that I would like to use to view/add/remove associates from
each project. So I think the rowsource for the listbox names namesList
would have to be populated with a query something like the following...

Me.NamesList.Ro wSource = _
"SELECT Associates.Last Name" & ", " & "Associates.Fir stName
" & _
"AS Name " & _
"FROM Associates" & _
"WHERE Me.ProjectID.Va lue = Assignments.Pro jectID " & _
"AND Assignments.Ass ociateID = Associates.Asso ciateID;"

Me.NamesList.Re query

....but this doesn't work. Could someone please help me with what this
query SHOULD look like?
Thanks!

Dec 5 '06 #1
3 8106

Prochot wrote:
I'm trying to design a database to track projects and the associates
assigned to them. I have almost no experience with this. I have three
tables:
-Projects
-Associates
-Assignments
where assignments contains projectID and associateID and is related to
the projects.projec tID primary key and the associates.asso ciateID
primary key. I have a form based on the projects table that contains a
list box that I would like to use to view/add/remove associates from
each project. So I think the rowsource for the listbox names namesList
would have to be populated with a query something like the following...

Me.NamesList.Ro wSource = _
"SELECT Associates.Last Name" & ", " & "Associates.Fir stName
" & _
"AS Name " & _
"FROM Associates" & _
"WHERE Me.ProjectID.Va lue = Assignments.Pro jectID " & _
"AND Assignments.Ass ociateID = Associates.Asso ciateID;"

Me.NamesList.Re query

...but this doesn't work. Could someone please help me with what this
query SHOULD look like?
Thanks!
You can't make a WHERE clause out of elements from different tables
without joining them. Take a look in the Access help under "Inner Join".

Dec 5 '06 #2
"Jamey Shuemaker" <ca*********@ya hoo.comwrote in
news:11******** **************@ j44g2000cwa.goo glegroups.com:
>
Prochot wrote:
>I'm trying to design a database to track projects and the
associates assigned to them. I have almost no experience
with this. I have three tables:
-Projects
-Associates
-Assignments
where assignments contains projectID and associateID and is
related to the projects.projec tID primary key and the
associates.ass ociateID primary key. I have a form based on
the projects table that contains a list box that I would like
to use to view/add/remove associates from each project. So I
think the rowsource for the listbox names namesList would
have to be populated with a query something like the
following...

Me.NamesList.Ro wSource = _
"SELECT Associates.Last Name" & ", " &
"Associates.Fir stName
" & _
"AS Name " & _
"FROM Associates" & _
"WHERE Me.ProjectID.Va lue = Assignments.Pro jectID
" & _ "AND Assignments.Ass ociateID =
Associates.Asso ciateID;"

Me.NamesList.Re query

...but this doesn't work. Could someone please help me with
what this query SHOULD look like?
Thanks!

You can't make a WHERE clause out of elements from different
tables without joining them. Take a look in the Access help
under "Inner Join".
Jamey, what you say here is wrong. It is perfectly legal to use
a where clause instead of a join. However, in the code given,
the FROM reference is missing the second table.

& " AS Name " _
& " FROM Associates, Assignments " _
& " WHERE ..."
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 6 '06 #3
"Prochot" <pr*****@gmail. comwrote in
news:11******** *************@j 72g2000cwa.goog legroups.com:
I'm trying to design a database to track projects and the
associates assigned to them. I have almost no experience with
this. I have three tables:
-Projects
-Associates
-Assignments
where assignments contains projectID and associateID and is
related to the projects.projec tID primary key and the
associates.asso ciateID primary key. I have a form based on
the projects table that contains a list box that I would like
to use to view/add/remove associates from each project. So I
think the rowsource for the listbox names namesList would have
to be populated with a query something like the following...

Me.NamesList.Ro wSource = _
"SELECT Associates.Last Name" & ", " &
"Associates.Fir stName
" & _
"AS Name " & _
"FROM Associates" & _
"WHERE Me.ProjectID.Va lue = Assignments.Pro jectID
" & _ "AND Assignments.Ass ociateID =
Associates.Asso ciateID;"

Me.NamesList.Re query

...but this doesn't work. Could someone please help me with
what this query SHOULD look like?
Thanks!
the reference to me.projectID needs to be outside the quotes if
used as you try to, in visual basic.

if project id is a numeric type"
"WHERE Assignments.Pro jectID = " & Me.ProjectID.Va lue & ...
if it's a text type field, you need embedded quotes
"WHERE Assignments.Pro jectID = """ & Me.ProjectID.Va lue & """...
(note that to embed a quote you put two side by side. The third
actually delimits the string.

But since you want to add/remove you are going to have problems,
since you are filtering on the selected project and associates.
I usually set up two (2) listboxes, one for the people already
assigned and a second listbox for the candidates to be added.

I'd set up the first, using an IN clause with a subquery.

SELECT name
FROM associates
WHERE associateID
IN (
SELECT AssociateID
FROM Assignments
WHERE projectID = forms!formname! ProjectID
);

I'm using the form's long name because me.project ID won't work
directly pasted into the rowsource of the listbox. It's a lot
simpler than mucking about generating the SQL in VB and
programatically stuffing it to the rowsource. You have the
choice.

for the second listbox, use the same SQL, but add the word NOT
before the IN.

Now you need two buttons on the form, one to add and one to
remove an associate. I would use a SQL INSERT INTO query and a
SQL DELETE FROM query with the proper filters,
Then after the SQL simply requery the two listboxes.

You also need to issue the requery statements in the CURRENT
event of the form.

Good luck.
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2010
by: Colleyville Alan | last post by:
I have an app in which users are displayed a list of mutual fund from which they can choose. There is a listbox embedded in a two-tabbed notebook control. When the form is initally opened, the listbox loads info: Private Sub Form_Open(Cancel As Integer) TabControl.Value = 0 Tab_Label1.Caption = "Select Alternatives from the Select List" FundAlternativesList.RowSource = "Load_Select_Alternatives_Form" Call Highlight_Defaults End Sub
2
3678
by: Simon P | last post by:
Hello group, I'm in desperate need of help. Here goes : I have the following tables : CONTACTS (ContactID, FirstName, LastName, Company, etc.), SHOWS (ShowID, ShowDescription) and SHOWDETAILS (links the previous tables together so not to have a many-to-many relationship -- has the ContactID and ShowID fields). I have a main form with a couple of listboxes which are used for querying the CONTACTS table. The results populate bound fields...
9
7026
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have it return the associated records to a listbox. Once the listbox has the records, I want to select a record, which will open a form associated with the selected record in the listbox.
3
3615
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name in the subform. Is it possible? How do I do this? Thanks in advance. Paul from Slovakia
2
4614
by: Geir Baardsen | last post by:
Hi! From a listbox I'd like to send only selected items to a report. Items will include: OrderNr,Date,EmployeeNr from tblOrders ZipCode,City from tblZipCodes Name,Adr,ZipID from tblCustomers OrderNr,ItemID,Amount,Price,Discount from tblOrderDetails
6
2466
by: AAJ | last post by:
Hi all I have a listbox on a form. If I set its rowsource directly, and the query in the rowsourse returns no data, then the displayed listbox is empty (exactly as you would expect) However.... If I programatically set the rowsource, and the query returns no records then access completely crashes and switches its self off,
1
3151
by: (PeteCresswell) | last post by:
One form, two list boxes. The left box's .RowSource is a query into a work table that selects items where !IsSelected = False. The rite box's .RowSource is a query into the same table that selects items where !IsSelected = True. If the user doubleclicks a row in the left listbox, DblClick event code sets !IsSelected=True, updates the record, and requeries both boxes.
3
2670
by: ML | last post by:
I have used Allen Brown's technique for filling a listbox on a form with the names of files in a certain disc folder. It works well. I am now giving the user the option to print the form contents in a report which has the same fields as the form. All fields derived from report query are OK A listbox with design mode rowsource setting, works fine BUT...
3
2489
by: deejayquai | last post by:
Hello Simple one this I guess, but I'm quite stuck at the moment. I would like to update the records displayed in my listbox (lstStudents) using criteria selected from my combo (cboForm) in a form. My basic code is:
0
9872
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...
1
9843
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,...
0
9713
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
8713
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
7248
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
6534
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();...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.