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

Lookups with Composite primary keys - How To?

mac
Summary:
1. I want to define a column in anMS Access table to be lookups on other
tables.
2. The table that is the data source (e.g the "parent" table) has a
composite
primary key.
3. When the "child" table does the lookup, it should pass all the columns
necessary
to properly restrict the data returned to the litbso for he lookup.
4. How do I accomplish this in a lookup?

Please, no suggestions to avoid lookups, etc. This is for a very quick and
dirty
"spreadsheet replacement" for a one time data mapping exercise I do
not have the time to write an app for this. I need to avoid code and just
use what I have
defined in the table structures and foreign keys.

The following example is fabricated, but it shows the idea. I know that the
keys in the example aren't ideal,
but it makes it easy to read the example.

ParentTable (Key is composite of (State, CityName):
[State], [CityName], [Population]
AZ Phoenix 1,000,000
GA Phoenix 8,000
AZ Tucson 500,000
ChildTable (Key is SalesmanID. State and CityName are part of a composite
foreign key that referes to the ParentTable.
[SalesmanID], [State], [CityName], [DateAssigned]
1 AZ Phoenix 1/15/2006
1 AZ Tucson 3/01/2006
3 GA Phoenix 1/15/2006
I want ChildTable.CityName to be a lookup possible values from ParentTable,
but I want the values shown in the lookup
to be restricted based on the State entered in the column ChildTable.State.
For example,
if you were in either of the first two rows of ChildTable, and hit the drop
down, you should see
'Phoenix' and 'Tucson'. If you were in the third row, you should only see
'Phoenix', but it would
be the Phoenix with a population of just 8,000 people.

If I define the column ChildTable.CityName as a lookup, I always see the
values Phoenix, Phoenix, Tucson, regardless
of which row I am on in Childtable.

How do I define the lookup so that the value from ChildTable is part of the
WHERE clause in the query that gets data
from ParentTable to populate the listbox? In other words, I want the query
to say WHERE State = 'AZ' when someone
invokes the lookup from one of the first two rows in ChildTable.

Thanks,

Mac
Sep 15 '06 #1
6 5391
Access != Excel.

use joins in a query.

Sep 15 '06 #2
Mac
I should not have even mentioned the "spreadsheet replacement". I am
well aware of the differences between databases and spreadsheets, and
I'm very comfortable with the concept of relational joins. I was just
trying to say that I want to define the lookup in the Access table
definition based on a composite key. Is this possible?

Thanks,

Mac
pi********@hotmail.com wrote:
Access != Excel.

use joins in a query.
Sep 15 '06 #3
Regardless of how "rushed" this may be, you should never be working directly
with tables. Creating a simple form, and then have a proper combobox do the
lookup for you doesn't take that much time.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Mac" <bm******@att.netwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>I should not have even mentioned the "spreadsheet replacement". I am
well aware of the differences between databases and spreadsheets, and
I'm very comfortable with the concept of relational joins. I was just
trying to say that I want to define the lookup in the Access table
definition based on a composite key. Is this possible?

Thanks,

Mac
pi********@hotmail.com wrote:
>Access != Excel.

use joins in a query.

Sep 15 '06 #4
Mac
Hi Doug,

Thanks for the info. However, my question is still unanswered. Can I
define a lookup in a table to work on a composite key?

Thanks,

Mac

Douglas J. Steele wrote:
Regardless of how "rushed" this may be, you should never be working directly
with tables. Creating a simple form, and then have a proper combobox do the
lookup for you doesn't take that much time.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Mac" <bm******@att.netwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
I should not have even mentioned the "spreadsheet replacement". I am
well aware of the differences between databases and spreadsheets, and
I'm very comfortable with the concept of relational joins. I was just
trying to say that I want to define the lookup in the Access table
definition based on a composite key. Is this possible?

Thanks,

Mac
pi********@hotmail.com wrote:
Access != Excel.

use joins in a query.
Sep 15 '06 #5
"Mac" <bm******@att.netwrote in message
<11**********************@b28g2000cwb.googlegroups .com>:
Hi Doug,

Thanks for the info. However, my question is still unanswered. Can I
define a lookup in a table to work on a composite key?

Thanks,

Mac
I think you can assume that the answer to that question, is the same
as the answer to the question - can the controlsource of a combo be
more than one field.

--
Roy-Vidar
Sep 15 '06 #6
Not as far as I know.

However, I will admit that my knowledge in this area is limited because a)
lookup fields are an abomination that should never have been introduced into
Access (see http://www.mvps.org/access/lookupfields.htm at "The Access Web"
for some of the reasons why) and b) you should never be working directly
with tables.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Mac" <bm******@att.netwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi Doug,

Thanks for the info. However, my question is still unanswered. Can I
define a lookup in a table to work on a composite key?

Thanks,

Mac

Douglas J. Steele wrote:
>Regardless of how "rushed" this may be, you should never be working
directly
with tables. Creating a simple form, and then have a proper combobox do
the
lookup for you doesn't take that much time.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Mac" <bm******@att.netwrote in message
news:11**********************@i42g2000cwa.googleg roups.com...
>I should not have even mentioned the "spreadsheet replacement". I am
well aware of the differences between databases and spreadsheets, and
I'm very comfortable with the concept of relational joins. I was just
trying to say that I want to define the lookup in the Access table
definition based on a composite key. Is this possible?

Thanks,

Mac
pi********@hotmail.com wrote:
Access != Excel.

use joins in a query.

Sep 15 '06 #7

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

Similar topics

0
by: Girish Agarwal | last post by:
--0-474210375-1058976151=:31789 Content-Type: text/plain; charset=us-ascii Content-Id: Content-Disposition: inline Note: forwarded message attached. __________________________________
5
by: John | last post by:
Specifically for joint tables... tblStudents tblClasses tblClasses_Students Is it be good programming to use a composite primary key in tblClasses_Students (where the key is ClassID and...
18
by: Thomas A. Anderson | last post by:
I am a bit confused in creating a composite primary key. I have three table with two of the tables containing primary keys. I have two of the tables (each with a primary key) having one to many...
4
by: Ismail Rajput | last post by:
Is there any option we can use Composite DataKeyField in the DataList and DataGrid?
2
by: bobby_b_ | last post by:
I have a table where fields 1 and 2 make up the primary key. Because of this, I have a unique composite index on fields 1 and 2 (as required by DB2). Now my question is: Fields 1 and 2 are also...
7
by: Ronald S. Cook | last post by:
My client manager likes concatenated/composite primary keys. I don't. Can anyone forward any arguments pro or con? Thanks, Ron
4
by: Wolfgang Keller | last post by:
Hello, so far it seems to me as if the only ORM module for Python which supports composite primary/foreign keys was SQLAlchemy. Which looks a little bit "overbloated" for my needs: I "just" need...
2
by: lfhenry | last post by:
Hi All, I am about to make some changes to a process we have. The new process will have a new table who's job it is to store temporarily data such as customer, clerkno,productno, storeno , amount,...
54
by: csolomon | last post by:
Hello: I was wondering if I could get some input on how to address a design issue, involving my composite table. I have one portion of my project complete. The following forms and reports I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: 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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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...

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.