Lost in "population"!

S

SpaceCadet!

Or maybe I'm not using the right terminology...

I have a database with 3 tables: Agents, Location, & Officers. All 3
tables have 2 fields that are (or should be) the same: Company Name &
Company Number.

When I enter data on any of these tables, I use a lookup column based on
"Company Name", AND I would like to have the Company Number automatically
fill in once I have selected the name.

Been looking at this data for far too long...and I'm probably thinking too
hard about it...

Thanks for ANY and all help!!
 
S

SpaceCadet!

Addendum:

My ultimate goal is to be able to enter data via a form...

But I would like to make sure that my data is connecting correctly before
going thru the whole she-bang of making a form...getting frustrated, deleting
it...over and over again.

Thanks!!
 
B

BruceM

You need a Company table. If an agent is associated with a Company you
could store the Company in the Agent table, but only the ID (the primary
key) from the Company table (tblCompany).

tblCompany
CompanyID (primary key, or PK)
CompanyName
Other company-specific information

tblAgent
AgentID (PK)
CompanyID (foreign key, or FK)
AgentFName
AgentLName
etc.

When you build an Agent form based on tblAgent (or on a query based on
tblAgent) you can create a combo box bound to CompanyID, with a row source
based on tblCompany. Set the combo box column count to 2, the bound column
to 1, and the column widths to 0";1.5". Adjust the width of the second
column as needed. When you click the down arrow in the combo box you will
see the Company Name, but the field being stored is CompanyID (the column
with no width, and thus invisible to the user, but not to Access).
I am speaking in general terms. I don't know how Agents, Location, or
Officers fit into the general picture, or how they are related to each
other. I have outlined a situation in which each agent is associated with
one company. However, if each agent may be associated with more than one
company, and a company may have more than one agent, there is a many-to-many
relationship, which requires another table. I will leave it at that for
now, but can add more information depending on your specific situation.
 
P

Pat Hartman

The linking field should be CompanyNumber rather than CompanyName. Use a
combo. The RowSource will be a query that selects CompanyNumber and
CompanyName and orders by CompanyName. The bound column will be 1, The
column count will be 2, the column widths will be 0";2" <--- that will hide
the first column (number) and show the second (name).

If you actually want to see the number on the form, add an unbound control
to the form and set its ControlSource to:
=cboCompanyNumber.Column(0)
 
S

SpaceCadet!

Ok...so now I have 4 tables. (License # could be considered my primary key
in any of them, as there are NO duplicates) (Company & Agent could be used
interchangeably)

Company
License #
Company Name

Agent
Company Name
License #
App Status
Address
City
State
ZIP

Location (as the company may have other offices)
Company Name
License #
Location Address
Location City
Location State
Location ZIP

Officers
Company Name
License #
Officer Name
Officer Address
Officer City
Officer State
Officer ZIP


How do I link/relate all if the tables, so when I'm adding data to any of
them, I use my lookup column (Company Name) and the next field (License #) is
automatically populated from the "Company" table.

Thanks!! (sorry to be a pain....I don't know much about Access...probably
enough to be dangerous!)
 
J

John W. Vinson

Or maybe I'm not using the right terminology...

I have a database with 3 tables: Agents, Location, & Officers. All 3
tables have 2 fields that are (or should be) the same: Company Name &
Company Number.

The company name should be stored ONCE, and once only, in the Company table
that you have yet to create. The company number is the only field you need in
any of the other tables.
When I enter data on any of these tables, I use a lookup column based on
"Company Name", AND I would like to have the Company Number automatically
fill in once I have selected the name.

See http://www.mvps.org/access/lookupfields.htm for a critique of the Lookup
Field misfeature. If you're working in your Tables... don't. Tables are for
data storage; use Forms for data entry and editing. It's very easy to put a
Combo Box (a "lookup" if you wish) on a Form, it's not necessary to use a
lookup field in the table in order to do so. The combo can display the company
name while storing the company number if you wish.
Been looking at this data for far too long...and I'm probably thinking too
hard about it...

or painting yourself in a corner by thinking about it in only one way... been
there, done that many a time!

John W. Vinson [MVP]
 
B

BruceM

I wasn't very thorough in my explanation. Each record is unique. In the
case of a Location table, the combination of Name, Address, City, etc. makes
up a unique record. There may be other entitites with the same city, etc.,
but the combination for a particular entity is unique. A field is often
added to a table in order to provide a convenient unique identifier for a
record. This field is known if Access as the primary key. It can be a
combination of fields, but it can also be a single field. By way of
example, an Employee table will usually include an Employee ID number by
which the employee is identified. No matter if the employee's name changes,
or the employee is transferred to another department, or whatever, the
number does not change.
When I suggested you add a Company table I did not realize that Company and
Agent are interchangeable. Remember that we cannot see your database, so
must rely on your description of it.
Who actually has the license? The company? The location? The agent? The
officer?
You say that a company may have several offices. Let me suggest an approach
that may help you understand the relationships between tables. Create a
company table (tblCompany) and a location table (tblLocation).

tblCompany
CompanyID (PK - may be autonumber)
CompanyName
Other company-specific information

tblLocation
LocationID (PK)
CompanyID (foreign key, or FK)
LocationAddress
Other location-specific information

The PK is established in table design view, but the so-called FK (not
everybody uses that term) is established when you create a relationship.
Click Tools > Relationships. Now click Relationships > Show Table (or use
the toolbar icon). Add both tables, then click OK. Drag CompanyID from one
table and drop it on CompanyID from the other table. Click Enforce
Referential Integrity in the window that appears. Close the Relationships
window.
You have modeled the situation in which a single company may have any number
of locations (one-to-many relationship).
Create a form (frmCompany) based on tblCompany, and another (fsubLocation)
based on tblCompany. With tblCompany open in design view, drag the icon for
fsubLocation onto it. This is one way to create a subform. Click the edge
of the subform, then click View > Properties. The window that appears is
the called the property sheet. Be sure that the Link Master and Link Child
properties both show CompanyID.
You can now add a company to tblCompany by way of the main form. When that
is done, you can add locations by way of the subform.
If Acme Company is number 123 in the Company table, each Location that you
enter in the subform automatically has 123 in the CompanyID field. This
field is what links the parent records (Company) to the child records
(Locations). No other company's locations have 123 in the Company field in
the Location table. By linking the child and master fields in the subform
control, as described, the linking field is added automatically to the child
table when you enter a record by way of the form/subform.
I realize there is more to the project than I have described, but this is
both an illustration and something you will probably need to do anyhow.
 
M

Maarkr

John, I've wanted to ask about the A2007 lookup feature in form combos...
since they have made it simple to keep adding lookup field info, does this
make the use of a lookup table for the combo obsolete, for the most part? or
is there a 255 char limit?
 
J

John W. Vinson

John, I've wanted to ask about the A2007 lookup feature in form combos...
since they have made it simple to keep adding lookup field info, does this
make the use of a lookup table for the combo obsolete, for the most part? or
is there a 255 char limit?

I don't have 2007 installed yet (it would interfere with my 2003 working
databases!), but I believe that Access is actually using a lookup table under
the hood, just keeping it concealed from view. The same limits would apply.

John W. Vinson [MVP]
 
Top