Lookup?

  • Thread starter Thread starter Jorge
  • Start date Start date
J

Jorge

Hi All..

I'm having a "major brainfart"
New at Access. I have a created two tables that link "emp#"
I've created a form that looks to the Employee database and lets the user
choose the "emp#".

What I'd like to do is place the employees First Name/ Lastname next to the
employee number chosen.
This is not editable.. but based on the emp# chosen..

What am I doing wrong?

Thanx
J
 
Hi All..

I'm having a "major brainfart"
New at Access. I have a created two tables that link "emp#"
I've created a form that looks to the Employee database and lets the user
choose the "emp#".

What I'd like to do is place the employees First Name/ Lastname next to the
employee number chosen.
This is not editable.. but based on the emp# chosen..

What am I doing wrong?

Thanx
J

Jorge,
Regarding: >> What am I doing wrong?<

You've told us what you would like to do, but haven't told us what you
have done that hasn't worked.

Here is one method.
In an unbound control's control source:

=DLookUp("[FirstName]","EmployeeTable","[EmpID] = " & [FormEmpID]) & "
" & DLookUp("[Last Name]","EmployeeTable","[EmpID] = " & [FormEmpID])

Change [FormEmpID] to whatever the contol name is on the form that
contains the EmpID number.
The above assumes [EmpID] is a number datatype.
 
When in table view it shows the drop down in the emp fiekd and the emp#'s
and names...
I created a form ( I'd like to do the same thing) and have the names just
appear next to the emp#.
Is there some sort of formula I should put in an unbound field?

If Emp# = to [Employee.Emp#] then Lastname

Any help?
 
Jorge said:
Hi All..

I'm having a "major brainfart"
New at Access. I have a created two tables that link "emp#"
I've created a form that looks to the Employee database and lets the
user choose the "emp#".

What I'd like to do is place the employees First Name/ Lastname next
to the employee number chosen.
This is not editable.. but based on the emp# chosen..

What am I doing wrong?

Thanx
J

I'm not sure I understand your problem correctly, so I'm going to guess.
I guess you have a table named, maybe, Employees, containing fields Emp#
(primary key), FirstName, and LastName. You have another table (name
unspecified) that also has an Emp# field, and you have a form based on
this table. The Emp# in this table (and on this form) is supposed to be
chosen from the values in the Employees table. I imagine that you have
a combo box on the form that has the Employees table as its row source.
Now you want to display the selected employee's FirstName and LastName
in text boxes on the form.

One way to do this is to make sure the combo box's row source selects
all three fields, Emp#, FirstName, and LastName, from the Employees
table, and also set the combo box's Column Count property to 3. You may
choose to set the Column Widths property to make all three columns
nicely visible when you drop down the combo's list, but only the first
visible column -- presumably Emp# -- will be displayed when the combo is
not dropped down. Having set up your combo box this way, you can add
two unbound text boxes to your form, named maybe "txtEmpFirstName" and
"txtEmpLastName". Assuming that your combo box is named "Emp#", set the
Control Source of txtEmpFirstName to

=[Emp#].[Column](1)

and set the Control Source of txtEmpLastName to

=[Emp#].[Column](2)

Note: the above is based on the combo box being named "Emp#". If your
combo box is actually named something else, just change that in the
control sources.
 
Dirk

LOL - Yes your assumptions are pretty much on the nose.
I will try all in the morning.


Would you think I would use the same type of scenario with a YES/NO field in
the database?
i.e...

If a check mark is in a YES/NO field then it would pull several fields data
for viewing NOT updating.
If a user selects DOG (check mark)
Then it looks in the DOG database and pulls FOOD, CARRIER cost.

Whatcha think sir?

Thank you!
J

Dirk Goldgar said:
Jorge said:
Hi All..

I'm having a "major brainfart"
New at Access. I have a created two tables that link "emp#"
I've created a form that looks to the Employee database and lets the
user choose the "emp#".

What I'd like to do is place the employees First Name/ Lastname next
to the employee number chosen.
This is not editable.. but based on the emp# chosen..

What am I doing wrong?

Thanx
J

I'm not sure I understand your problem correctly, so I'm going to guess.
I guess you have a table named, maybe, Employees, containing fields Emp#
(primary key), FirstName, and LastName. You have another table (name
unspecified) that also has an Emp# field, and you have a form based on
this table. The Emp# in this table (and on this form) is supposed to be
chosen from the values in the Employees table. I imagine that you have
a combo box on the form that has the Employees table as its row source.
Now you want to display the selected employee's FirstName and LastName
in text boxes on the form.

One way to do this is to make sure the combo box's row source selects
all three fields, Emp#, FirstName, and LastName, from the Employees
table, and also set the combo box's Column Count property to 3. You may
choose to set the Column Widths property to make all three columns
nicely visible when you drop down the combo's list, but only the first
visible column -- presumably Emp# -- will be displayed when the combo is
not dropped down. Having set up your combo box this way, you can add
two unbound text boxes to your form, named maybe "txtEmpFirstName" and
"txtEmpLastName". Assuming that your combo box is named "Emp#", set the
Control Source of txtEmpFirstName to

=[Emp#].[Column](1)

and set the Control Source of txtEmpLastName to

=[Emp#].[Column](2)

Note: the above is based on the combo box being named "Emp#". If your
combo box is actually named something else, just change that in the
control sources.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Jorge said:
Dirk

LOL - Yes your assumptions are pretty much on the nose.
I will try all in the morning.


Would you think I would use the same type of scenario with a YES/NO
field in the database?
i.e...

If a check mark is in a YES/NO field then it would pull several
fields data for viewing NOT updating.
If a user selects DOG (check mark)
Then it looks in the DOG database and pulls FOOD, CARRIER cost.

Whatcha think sir?

It sounds like a substantially different scenario to me, and I think a
different approach would be called for. When you say "the DOG
database", do you actually mean a different database, or do you really
mean just a different *table* in the current database? Either way, I'd
need a much more complete understanding of your tables, their
relationships, and what you're trying to achieve before I could offer
any worthwhile advice.
 
Either way, I'd
need a much more complete understanding of your tables, their
relationships, and what you're trying to achieve before I could offer
any worthwhile advice.

..... didn't stop you before, Dirk! Your Palantir getting cloudy? <g>

Fred
 
OK I'll try..

DOG.db, CAT.db, RECV.db

DOG has Food$, Carrier$, Shots$ Primary key = A
CAT has Food$, Carrier$, Shots$ Primary key = B
These 2 db's can only have one entry pertaining to food etc
So would you call these a table? I suppose.
I have the record set to 1.

RECV has Name, Address etc.. and type of transaction (DOG or CAT)
Based on a check mark (on/off) in DOG or CAT it will display the current
fields within either Dog or Cat for Food$, Carrier$, Shots$
Does this sound okay?

|X| | | -------------------------
DOG CAT | Dog Food $5 |
| Dog Carrier $5 |
| Dog Shots $5 |
| |
--------------------------

The dog & cat & Recv databases have quite a few more entries but I am just
trying to keep it simple.

Thank -u
Jorge
 
Jorge said:
OK I'll try..

DOG.db, CAT.db, RECV.db

DOG has Food$, Carrier$, Shots$ Primary key = A
CAT has Food$, Carrier$, Shots$ Primary key = B
These 2 db's can only have one entry pertaining to food etc
So would you call these a table? I suppose.
I have the record set to 1.

RECV has Name, Address etc.. and type of transaction (DOG or CAT)
Based on a check mark (on/off) in DOG or CAT it will display the
current fields within either Dog or Cat for Food$, Carrier$, Shots$
Does this sound okay?

DOG CAT | Dog Food $5 |
| Dog Carrier $5 |
| Dog Shots $5 |
|
| --------------------------

The dog & cat & Recv databases have quite a few more entries but I am
just trying to keep it simple.

Thank -u
Jorge

I have a technical question and a design comment. The technical
question is, are you in fact working with Microsoft Access? Where do
these ".db" file types (?) come from? Are you using Access, but linking
to tables/files from another database system, possibly xBase? Or are
you working within another database system entirely? If the latter, my
design comment would still apply, I think, but I can't offer much in the
way of technical advice.

Now for the design comment. I'll assume that your DOG.db, CAT.db, and
RECV.db represent what are either in fact or in practice, three logical
tables. I understand that what you've posted is a simplification of the
actual design. For the purposes of this discussion, I'll consider that
"DOG" is a table, "CAT" is a table, and "RECV" is a table of
transactions involving the first two tables. But this design is flawed,
because you are storing essential information in the table name (DOG vs.
CAT) itself.

If DOG and CAT contain a set of fields that they hold in common, and
which you need to work with (as far as RECV is concerned) as though
there were no difference between the two tables except for the fact that
a particular record happens to represent a dog or a cat, then those
fields should really be stored in a single table. That table would
abstract this essential quality of dogs and cats. For example, you
would do better to have a table called (maybe) ANIMAL which would
contain these fields:

Table: ANIMAL
Field: AnimalID (primary key)
Field: AnimalType (dog, cat, goldfish, whatever)
Field: Food
Field: Carrier
Field: Shots

This ANIMAL table and its key AnimalID would then be referred to by your
RECV transaction table, rather than any individual table for each animal
type.

You may or may not need additional, special fields that are specific to
each type of animal. This is a sub-typing arrangement -- CAT is a
subtype of ANIMAL. In such a case, you could either include the special
fields for each animal in the ANIMAL table and show them as needed, or
you could have a set of separate tables, one for each type of animal,
with each of these tables in a one-to-one relationship with the ANIMAL
table (ANIMAL being primary, however). That way, you could have
separate forms for each type of animal if you want, basing each on a
query that joins the ANIMAL table with the appropriate subtype table,
and you could also have a form based on ANIMAL alone, but show an
appropriate subform based on the AnimalType of the current record
(swapping or showing and hiding subforms as needed).
 
Dirk sir...

I appreciate your advice.
My bad, regarding the DB.. Access is MDB - oooops...
The tables are Access.

I originally had Dog/Cat as one table and I'd been running into problems -
so I thought maybe if i split them...
The dog/cat tables have quite a few fields that are the same or contain the
same information.
But some of them are different... Like dog cost is $8,cat is $6.. dog shots
are $38, cat shots are $20...
I was simply trying to place the information on a form... depending on the
selection in RECV.

Lets say a user checks DOG they see all the default costs regarding DOG....
Dog shots, dog food, dog carrier... the user can then print the report or
invoice without having to select anymore.
or
They get the default costs associated with DOG, and check Rabies Shot which
adds $10 to the default cost and Dog Sterilization which adds another $38.

The same thing with CAT if a user selects CAT.

Will the scenario you had suggested perform this?
I'm a freshly in Access and muddling through it best I can.
Learn by doing - huh?

Thank-You
George
 
Dirk
You had commented..

'for each animal in the ANIMAL table and show them as needed, or
you could have a set of separate tables, one for each type of animal,
with each of these tables in a one-to-one relationship with the ANIMAL
table (ANIMAL being primary, however)"

When I separated and had DOG & CAT - I suppose I was thinking the same
thing?
But unfortunately I'm not Access savvy (yet) and putting the code in is an
challenge..
My boss says this "should be simple" and keeps ragging me.. he's just funnin
me.
I guess the folks will have keep entering everything by hand and paper until
I can get this working..

Thanx sir.
 
(Comments inline ...)

Jorge said:
Dirk sir...

I appreciate your advice.
My bad, regarding the DB.. Access is MDB - oooops...
The tables are Access.

That's fine, but I hope you don't have separate MDB *files* for each of
these tables. We must distinguish between a *database* -- the container
that holds your tables -- and the tables themselves. Unless you have
unusual circumstances, you should have one MDB file containing all the
tables used by your application.
I originally had Dog/Cat as one table and I'd been running into
problems - so I thought maybe if i split them...
The dog/cat tables have quite a few fields that are the same or
contain the same information.
But some of them are different... Like dog cost is $8,cat is $6.. dog
shots are $38, cat shots are $20...
I was simply trying to place the information on a form... depending
on the selection in RECV.

Lets say a user checks DOG they see all the default costs regarding
DOG.... Dog shots, dog food, dog carrier... the user can then print
the report or invoice without having to select anymore.
or
They get the default costs associated with DOG, and check Rabies Shot
which adds $10 to the default cost and Dog Sterilization which adds
another $38.

The same thing with CAT if a user selects CAT.

Will the scenario you had suggested perform this?
I'm a freshly in Access and muddling through it best I can.
Learn by doing - huh?

Learning by doing is good. You do have to think or study a bit about
how databases work.

It seems to me you need a table that specifies the costs by animal type.
There are a couple of ways you might set this up. For maximum
flexibility, I'd be inclined to have a table of services indexed by
ServiceCode, and another table of service charges indexed by both
ServiceCode and AnimalType, along these lines:

Table: Services
Field: ServiceCode (primary key)
Field: ServiceDescription (text)

Table: ServiceCharges
Field: ServiceCode (compound primary key)
Field: AnimalType (compound primary key)
Field: ServiceCharge (currency)

Examples of records in these tables might be

Services:
1, "Base charge"
2, "Carrier"
3, "Shots"
4, "Rabies shot"
5, "Sterilization"

ServiceCharges:
1, cat, $6
1, dog, $8
2, cat, $5
2, dog, $10
3, cat, $20
3, dog, $38
4, cat, $10
4, dog, $10
5, cat, $30
5, dog, $38

This would give you a mechanism for creating invoices by selecting an
animal on a main form, then selecting a service on a subform to create
an invoice line, automatically bringing in the appropriate charge for
the service code and type of animal. Note that now you're talking about
additional tables: Invoices as the basis of the main form, and
InvoiceDetails and the basis of the subform.
 
Jorge said:
Dirk
You had commented..

'for each animal in the ANIMAL table and show them as needed, or
you could have a set of separate tables, one for each type of animal,
with each of these tables in a one-to-one relationship with the ANIMAL
table (ANIMAL being primary, however)"

When I separated and had DOG & CAT - I suppose I was thinking the same
thing?
But unfortunately I'm not Access savvy (yet) and putting the code in
is an challenge..
My boss says this "should be simple" and keeps ragging me.. he's just
funnin me.
I guess the folks will have keep entering everything by hand and
paper until I can get this working..

Thanx sir.

Well, since you have never even described the business process you're
trying to support, there's a limited amount of help I can give you. But
it sounds like you're trying to do invoicing for a veterinarian, or
possibly for an animal shelter. No matter how simple it seems, any
database application beyond a simple catalog requires considerable
forethought before you put fingers to keyboard. If you get the data
design right, then Access makes the development of the finished
application quite simple. But you have to get the data design right
first.
 
You would be correct again!

If someone claims the animal, he just wants the person to go to front desk
Enter their name, address, choose which employee performed the task and
enter dog/cat etc - print the invoice and tada...

Thx...
 
Mr. Goldgar

look inline please..

Dirk Goldgar said:
(Comments inline ...)



That's fine, but I hope you don't have separate MDB *files* for each of
these tables. We must distinguish between a *database* -- the container
that holds your tables -- and the tables themselves. Unless you have
unusual circumstances, you should have one MDB file containing all the
tables used by your application.


Learning by doing is good. You do have to think or study a bit about
how databases work.

It seems to me you need a table that specifies the costs by animal type.
There are a couple of ways you might set this up. For maximum
flexibility, I'd be inclined to have a table of services indexed by
ServiceCode, and another table of service charges indexed by both
ServiceCode and AnimalType, along these lines:

Table: Services
Field: ServiceCode (primary key)
Field: ServiceDescription (text)

Table: ServiceCharges
Field: ServiceCode (compound primary key)
Field: AnimalType (compound primary key)
Field: ServiceCharge (currency)

Examples of records in these tables might be

Services:
1, "Base charge"
2, "Carrier"
3, "Shots"
4, "Rabies shot"
5, "Sterilization"

ServiceCharges:
1, cat, $6
1, dog, $8
2, cat, $5
2, dog, $10
3, cat, $20
3, dog, $38
4, cat, $10
4, dog, $10
5, cat, $30
5, dog, $38

I have created 2 two tables as above.
In all I have 14 different services that can be selected.
Here is what I have thusfar. 4 tables..

Employee Receive Services ServiceCharges

EmpID#(autonumb) primary key Rec#(autonum) primary key ServiceCode (primary key) ServiceCode (primary key)
EmpFname RecFname ServiceDesc AnimalType
EmpLname RecLname ServiceCharge
EmpAddr RecPhone
EmpCity EmpID# (this looks up to Employee)
EmpSt ServiceCode (this looks up to Services)
EmpZip
EmpPhone


I can see how this may be better...
In the Receive table, do I put 14 instances for the Service that could be selected? and have it lookup to the Servicecharges table?

Receive is the only table that will have multiple records.
Once the employee, services, servicecharges have been placed within.
They will be changed only when a new is entered or adjusted.

Relationships:
Service - one to one - ServiceCharges
Receive - many to one - Employee
Receive - many to many - Service

Does this look right?

Thank-you almighty access guru...
 
Back
Top