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

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.projectID primary key and the associates.associateID
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.RowSource = _
"SELECT Associates.LastName" & ", " & "Associates.FirstName
" & _
"AS Name " & _
"FROM Associates" & _
"WHERE Me.ProjectID.Value = Assignments.ProjectID " & _
"AND Assignments.AssociateID = Associates.AssociateID;"

Me.NamesList.Requery

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

Dec 5 '06 #1
3 8084

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.projectID primary key and the associates.associateID
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.RowSource = _
"SELECT Associates.LastName" & ", " & "Associates.FirstName
" & _
"AS Name " & _
"FROM Associates" & _
"WHERE Me.ProjectID.Value = Assignments.ProjectID " & _
"AND Assignments.AssociateID = Associates.AssociateID;"

Me.NamesList.Requery

...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*********@yahoo.comwrote in
news:11**********************@j44g2000cwa.googlegr oups.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.projectID primary key and the
associates.associateID 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.RowSource = _
"SELECT Associates.LastName" & ", " &
"Associates.FirstName
" & _
"AS Name " & _
"FROM Associates" & _
"WHERE Me.ProjectID.Value = Assignments.ProjectID
" & _ "AND Assignments.AssociateID =
Associates.AssociateID;"

Me.NamesList.Requery

...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*********************@j72g2000cwa.googlegro ups.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.projectID primary key and the
associates.associateID 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.RowSource = _
"SELECT Associates.LastName" & ", " &
"Associates.FirstName
" & _
"AS Name " & _
"FROM Associates" & _
"WHERE Me.ProjectID.Value = Assignments.ProjectID
" & _ "AND Assignments.AssociateID =
Associates.AssociateID;"

Me.NamesList.Requery

...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.ProjectID = " & Me.ProjectID.Value & ...
if it's a text type field, you need embedded quotes
"WHERE Assignments.ProjectID = """ & Me.ProjectID.Value & """...
(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
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...
2
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...
9
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...
3
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...
2
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...
6
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) ...
1
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...
3
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...
3
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.