General :: Access 2007 / Finding A Related Record That Has 2 Foreign Keys?
Jan 22, 2013
I am using access 2007
i have a materialsUsed tbl that list all the materials used in a job and the quantity of each.
(ID
Material Code
Quantity
Unit of Measure)
I also have 2 look-up tables - 1 for the material codes and 1 for the units of measure
I have another table, priceperunitofMeasure
id
material Code (FK to material lookup tbl)
Unit of Measure (FK to unit of measure tbl)
Price
In my form Users will select material code from combo box - enter the quantity, and select a unit of measure from a combo box.
For example: they could enter the following :
Paint 2 gallons
Paint 3 tubes
Paint 1 pint
How do I lookup the price per unit of measure for each of these records in the price per unit of meassure table? The price per unit of measure table has 2 foreign keys.
I have to create a database for work and for my sins I have to use Access. We are running 2007 but I'm having some difficulty in creating foreign keys in my linking table. I've searched their help guide and looked on the net but I can't seem to see how I physically create foreign keys.
My structure looks like this:
Customer CustID (autonumber) Cust Name Cust contact Cust email cust version no of users other info
Modules ModID (autonumber) Module name licensed module? (tick box)
MiscSoftware MiscID (autonumber) Software Installed on live
I'm not new to access, and I understand normalization at pretty much all its levels, but right now I'm curious about a situation that I have just come across. The first time I've been in something like this, so I thought I would ask.
This is the setup.
I have employees. They are apart of a shift and a budget. Shifts and budgets are completely independent of each other.
The database needs to keep track of shifts and budgets over time. Therefore, 1 to many relationship to shift table and budget table.
But, the database also needs to keep track of attendance. And the user wants attendance tracked by Shift and Budget.
Shift and budget are completely independent of each other.
Currently, I have the relationships set up like this.
When a new attendance record needs to be added, both the key to the budget and shift are added to the attendance table. The key chosen is dependant onthe Employee chosen, and whether the budget and shift are the CURRENT budget and shift that the employee is apart of.
I thought of running a query showing budget and shift by date descending, so that the latest budget / shift would be displayed, and thus the most current (SUPPOSEDLY) But, if a user put in a different date, or screwed up on the date, then the incorrect shift and/or budget would be displayed.
Date stamping an entry was an option, but there needed to also be a user entered date as well, to specify WHEN a user began working in that specific budget / shift. Therefore two date entries would be required. Duplicate entries in most cases.
I therefore decided to go with a true/false yes/no checkbox. Where the current budget or shift would be checked, and all non current ones would be unchecked (false).
Currently, this is how the systems works. And it works well. But it is dependent on some form code I created to set the yes/no checkbox to true/false depending on the situation.
I DON"T like doing this. Am I missing a way to do this "correctly" where by Access would do this "automagically" instead of via my trick.
The ONLY issue really, is that when a new attendance incident occurs, the user needs to put in the incident to the approbriate shift / budget. And if the current shift / budget could automatically be displayed without user intervention (IE user has to pick the shift / budget from drop down box after looking up info etc etc) since the current information SHOULD be known.
I've never done a table setup where two foreign keys are the many side of the relationship in a single table.
It is currently working fine, and seems to do well, but I wanted to make sure with others who might have had this experience. And also, any "advice" / "cautions" for this kind of situation so I don't step into it deep and have to fix it later.
Builder Subdivision Lot Number Lot Option Lot Materials Details
The [Lot Materials Details] table is populated by appending data from the [House Type Details] table tree as follows:
Builder House Type Elevation Options Per Elevation House Type Materials Details
The filtered Option Table in both branches determine which [House Type Materials Details] records get appended to the [Lot Materials Details] table.
The question is: Is there any advantage, other than simpler queries later on, to adding the primary key from the [House Type Materials Details] table to the [Lot Materials Details] table.
It’s redundant because the [Lot Options Table] contains the [Options Per Elevation] primary key.
hi i need to create a table, i've figured out to make LastName the primary key. But im not so sure about the foreign key, and whether it is necessary to put it into the table in order for all my tables to relate? Sorry if this doesn't make much sense. Also, to clarify.. 3NF primary keys in one table cannot be used in another table?? thanks
Wow, I've found some good stuff here already... Thanks.
PROBLEM: I have a table(we'll call it shipping) that has two columns FK'ed to another table (locations). My problem is I have no idea how to pull the information from the locations table into the shipping table.
DESCRIPTION: My shipping table has a source and a destination column. Now, I have a fixed location list that applies to both columns and I'd like to avoid having a source tbl and a destination tbl... I'm an Access Neophyte to say the least (for now at least) but I have managed to put together a querie that pulls out most of the information that I need (name, phone number, yadda, yadda, yadda) but I can't seem to correctly link the FK's for the sources to the locations table as well as the FK's for the destinations to the locations table. When I run my querie I get an error or my Source(destination) column will display the correct information but the Destination(source) column will display ALL of the locations in the location table. Here's what I mean:
Source destination detroit toledo detroit cleveland detroit San Diego detroit London detroit Paris detroit detroit Paris toledo Paris cleveland Paris San Diego Paris London Paris Paris Paris detroit
. . .
The first and second source was detroit and Paris but the Destinations list all of the locations I have in the table.
How can I link two FK's in one table to another table in a querie?
When attempting to print a report in Access which was setup to print to a specific printer I am getting the following message.
This document was previously formatted for [printer name] which is currently not available. Do you want to use the default printer [printer name]
I don't understand because the printer and port name it is referencing is available and matches perfectly! I've tried removing the printer and deleting the port and re-adding it with no success.
I am trying to model my database to create relationships between different tables in my database. During the process of doing so I ended up having one primary key in table A linked with to foreign keys in two different tables ( table B & table C) and both of those two table are junction tables to break out many to many between many other tables
Now for some reason!!! I feel that there is something wrong with my logic mapping and modeling of the relationships between tables due the fact of having one primary key linked to two foreign keys in two different tables :(
Is my intuition is right? should such case be considered as indicative of wrong modeling of relationships between tables in a single database And if so what is the disadvantages of that link (talking down the road) when the database if fully populated? :confused:
By the way I am new member and new to database, so please take it easy on me :o
I've got a table - "Products" - in my database, with a text field - "Info" - which contains info about products.
Within this field I would like to have footnotes. To do this, I think the best way to do it is by putting numbers inside the text at the location of where I want the footnote to refer to. These numbers will actually be foreign keys to a table called 'Footnotes'.
I can then program the forms and reports to show any numbers as superscripts or whatever.
(Of course, if the user will actually want to insert a number into the text field which is NOT a reference to a footnote, I will have to make a workaround e.g. by making access put a symbol in front of the number, so access will know the number is just part of the text (and I will program the form to not show the symbol in front of the number)).
Is it wrong to have foreign keys within a text field? I think if executed correctly, it should work perfectly.
I have what I think is a normalised database that uses foreign keys quite a bit.
For example if I had a 'contracts' table which refers to 'clients', then there would be a tblClients, where each client has a primary key. The tblContracts would then refer to the relevant client via that clients FK only which would be linked to the client's PK in tblClients via a one-to-many relationship.
If I need any user for any purpose to see contract related information that makes sense to a human being, I simply construct a query with the necessary relationships that will show client information alongside contract information by substituting tblContracts' client FK with required information from tblClients via the appropriate relationships.
I think that is reasonably basic stuff (hopefully correct practice!)
But what about when I come to import a block of new data that needs to go into tblContracts? I'm not going to be given a list of client keys (obviously) I'm going to given their real names.
MS Access has (in theory) all the information it needs (via the relationships) to substitute client IDs (keys) for their real names and thus slot these IDs into tblContracts with the new data as appropriate, but how do I make it do this? (I know it could kick out errors if there are any duplicate client names, but let's put that to one side for a moment).
Right now, I have 4 related tables. There's a table with companies, one with people involved with companies, a table linking the two by having foreign keys of the company number and people names, and a table that indicates directors and their alternates.
Since there's a one-to-many relationship for companies/people to company-peopleID (A person can run multiple companies, a company has multiple directors, it's easier this way), a person's name can appear multiple times, as can a company, within that table.
In a company, a director may or may not have 1 and only 1 alternate director to him/herself. So, I thought the easiest way was to put an autonumber in the Company-personID table and have a table (alternates) that had two fields, "alternate" and "director", both using that autonumber to link them. However, it appears as though I can't link the same primary key twice to two foreign keys of the same table.
I'm developing a simple sporting records db. I have a 'Competitor' table listing competitors as follows: CompetitorPK, Name, Division, Club. I have a 'Contest' table listing contests as follows: ContestPK, Competitor1_FK, Competitor2_FK, Winner_FK, Score etc. My question is have I modelled tables correctly i.e. CompetitorPK will appear in three columns of Contest table. How do I define this relationship? What alternative is there to what I have done.I intend to use forms to populate both tables (independantly obviously).
I have 2 tables. 1- customers table with 2 fields : customername,customerno 2-conversationstable with 4 fields: date,customername,customerno,details
The conversations table is for keeping memo of telephone conversations with the customers.
I built a simple form deriving from the conversations table. And added to it a combobox with 2 columns from customers table to select the customername an customerno for the form.
While deleting the record in the conversations table,through the form, I saw that the customername and customerno in the customers table of that particular customer record are deleted also. I made no links between both tables.
I am pulling my hair out with what I am sure is a simple task, creating a search form that, when criteria are entered, finds a record and displays related data/results from 3 tables. I have tried every forum and web post I can find but I think there must be something fundamental I'm neglecting to grasp.
Quick background: My database has 4 tables, Firm, Contacts, Mailout and FileNote The database is contact-centric (ie, everything is linked to a contact record, multiple contacts are held against firms, mutiple file notes are held against a contact, contacts can be attached to multiple mailouts) I need to search for a contact record based on multiple criteria (keeping it simple, lets say a combination of first_name & last_name OR first-name & firm_name OR their specific contact ID) I need a 'results form' (not just a datasheet view) that displays all information related to that contact (i.e. all files notes + ability to create new ones, firm contact information, and mailout history)
I've created a Main form with Firm, Mailout, Contact & Filenote subforms embedded that enables me to scroll through every contact and view all related detail (as above) and add file notes & modify data very nicely. My problem is I can't search, I can only move through each record sequentially. Very handy when we have 4000 contacts!
I realise I'm probably a complete wally but could someone please explain to me the vital steps I'm missing? I've tried unbound fields, I've built SQL queries & command buttons (but results are dumped into a datasheet)....I'm lost.
Hi All - I'm developing a database that requires records to be entered and updated. When updating records, the user must select an item from switchboard (Update a Record) which takes them to a screen/form where the user can enter the record number. When the record number is entered and the user clicks on the "OK Button" I need one of two actions to occur ... (1) the user is taken to the record for updating or (2) the application returns a message "Record Not Found".
Can anyone tell me how I can code this?
At this time I get a message that my form name is not recognized within the expression I've "built" in the macro.
If anyone can help me it would be greatly appreciated before I go bald from pulling my hair out!!
I have a table called tblCompanies. When a company acquires another company, I need a method by which the acquired company's CompanyID (PK) can be updated to the new company's CompanyID (PK). I also need to be able to update all related CompanyIDs (FKs) to the new value in related tables.
In cases in which the new company does not have an existing record, there is no problem: the company name simply gets changed to the new company and the existing CompanyID is maintained. I then use an audit table and Track Changes function to keep track of the company name data and a union query to keep the old names in the selection lists.
The problem is when both companies already have existing records in the table.
So, let's say I have records for Company A and Company B. Company A merges with Company B and Company B is now the main record. What is the best, simplest and easiest way to update the CompanyID (PK) from A to B and change the CompanyID (FK) to the new value in all related tables?
I am envisioning a pop-up form that directs the user to select the new company and then an update query happens behind the scenes... but exactly how does the criteria for the update query get selected and how do all the related tables get updated? My vba skills are pretty basic, will I need extensive coding to do something like this?
I created 2 table that are linked to a link table so to get a many to many relationship.I have a table for locations and a table for parts.One location can have many parts and One part can belong to many locations, that is way the many to many relationship.
how to get values from the parts table to the Location table using the linked Primary Key in the foreign key linked field.The values also have to be interactive, if I change the value in the part table it needs to update in the location table.
What can I put in the field of the location table to get a specific value from the parts table?
I tried setting the field to calculated field and put the Dlookup function but that didn't work. The lookup wizard seems to be the solution, but I can only create combobox or list box and I need to select the value manually. I just need a value to be put automatically by looking at the foreign key.
If I put the Dlookup function on the default value, those it update if a value is changed in the part table?
I have a database that works fine on access 2000. The problem is that when I open it in Access 2007 the switchboard does not display correctly and my command buttons do not work. Also, my field that autofill from a combo box do not fill in. I am assuming that access 2007 does not recognize the code for all of these. If this is the problem does anyone know of a reference that can be used to change the code to work.
Also, thought I would mention that I opened it in Windows Vista. I have read about problems with Vista. I have not tried opening the database on a computer running XP.
Just wanting to get working now in case my company changes over to Office 2007 in the future.
It seems that if I have a continuous subform open and scroll down through the records, then hit Alt, the subform immediately scrolls back to the top again?
I only noticed this today when I scrolled to a particular record, then wanted to use Alt+Tab to switch to a different window. When I Alt+Tab'd back to my DB, the subform had scrolled back to the top and I had to scroll again to find my record. It was only then that I realised the auto-scroll was happening as soon as I hit the Alt key.
How to disable this behaviour as I use Alt+Tab pretty frequently (as do my users, more importantly) and it will get pretty annoying pretty quickly if the subform keeps reverting to the top?
I am upgrading an Access 2000 system to 2007 and replacing user toolbars with Ribbons.I have a strange parsing error that I think is not my error.
I have placed the following control into a group:
<control idMso="GroupPrintPreviewClosePreview" label="Close Preview" enabled="true"/> and "the system" rejects it with Error Code 0x80004005 Element <group> is not expected in <group>I
t turns out that it is finding the word Group within the double quotes and interpretting is at part of the XML syntax.
Change to another idMSO and the problem goes away. Same happened with another control that had the word Group in the id.