UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

> Showing data from a related table - need to use a subform?    
 
   
lkelly
post Sep 26 2005, 09:42 AM
Post #1

UtterAccess Member
Posts: 28



I have a table called "People" which has all sorts of info about each member of an organization. Name, address, etc. One portion of the table deals with whether or not they are an officer. That's a Yes/No field. If a person is an officer, I need to keep track of the year they became one. Instead of placing a field in the People table to simply store the year, I have used a second table called "FiscalYear" to keep track of the actual start and end date. In my People table I have the ID of the record in the FiscalYear table to determine when they became an officer. Hopefully that makes sense.

My question is how to show the StartYear field from the FiscalYear table on the form for People. I have the text box on the form, but right now it will just show the ID of the fiscal year. I simply need to look up the StartYear using that ID.

Do I need to use a subform for this since the actual data I want to display comes from the FiscalYear table, and not the People table?

Very simple question I'm sure, so thanks in advance for any help.
Go to the top of the page
 
+
 
Start new topic
Replies (1 - 11)
fkegley
post Sep 26 2005, 09:48 AM
Post #2

UtterAccess VIP
Posts: 23,583
From: Mississippi



Yes, but you're doing it backwards. In the FiscalYear table you should have the ID of the person along with the years he/she served as an officer. You probably should not need a Yes/No field in the People table. In the FiscalYear table, the ID of the person, the office he held, and the start date and end date of his term.

Then a form/subform will do the trick. You'll have one record in the FiscalYear table for each office a person has held.
Go to the top of the page
 
+
lkelly
post Sep 26 2005, 10:06 AM
Post #3

UtterAccess Member
Posts: 28



I'm actually using fiscal year for a variety of things in this database. When the person became a member of the organization, when they became an officer, as well as other areas like receipts of donations.

If we take the year the person joined the organization as a simpler example:

Person
...
FiscalYearID (to represent when they joined the organization)
...

FiscalYear
FiscalYearID
StartYear*
EndYear

* This is what I'd like to show on the form with data about each person.

Does this make sense, and is this the right approach? As I said, I need to use Fiscal Year elsewhere in the database as many things relate to it.
Go to the top of the page
 
+
lkelly
post Sep 26 2005, 10:09 AM
Post #4

UtterAccess Member
Posts: 28



Ah, just dawned on me that a combo box showing defined fiscal years would be more appropriate in this case.

New question is how to just show the date portion of the start date field in the combo box? My select statement will return something like "7/1/2004", but I really just want to show the "2004" part.

Thanks.

Edited by: lkelly on Mon Sep 26 11:29:09 EDT 2005.
Go to the top of the page
 
+
fkegley
post Sep 26 2005, 10:34 AM
Post #5

UtterAccess VIP
Posts: 23,583
From: Mississippi



I believe you can use the Year function to return just the year:

Year([DateFieldNameGoesHere])
Go to the top of the page
 
+
lkelly
post Sep 26 2005, 10:40 AM
Post #6

UtterAccess Member
Posts: 28



Where would this Year(...) formatting go? Around the select statement for the combo box? In the query itself. I'm unsure about the syntax.

Thanks.
Go to the top of the page
 
+
fkegley
post Sep 26 2005, 01:49 PM
Post #7

UtterAccess VIP
Posts: 23,583
From: Mississippi



I would put it in the query for the combo box.
Go to the top of the page
 
+
lkelly
post Sep 26 2005, 02:59 PM
Post #8

UtterAccess Member
Posts: 28



Thanks, but could you help with the syntax?

Right now it has the standard:

SELECT Fiscal_Year.Start_Year, Fiscal_Year.End_Year FROM Fiscal_Year;
Go to the top of the page
 
+
fkegley
post Sep 26 2005, 03:50 PM
Post #9

UtterAccess VIP
Posts: 23,583
From: Mississippi



SELECT Year(Fiscal_Year.Start_Year) As SY, Fiscal_Year.End_Year FROM Fiscal_Year
Go to the top of the page
 
+
fkegley
post Sep 26 2005, 03:59 PM
Post #10

UtterAccess VIP
Posts: 23,583
From: Mississippi



You're heading for trouble. The recommended way to store data is that each table should store data about exactly one thing. You should have for sure a separate table for donations, probably for other entities as well. Otherwise, you're going to have to use code or extremely complex queries to get what you want from the fiscal year table. The bottom line is that you will have to work very extremely harder than you would otherwise have to work.

Read up on normalization. Any good database reference book can tell you about it. This site also has loads of posts about normalization.
Go to the top of the page
 
+
lkelly
post Sep 26 2005, 04:03 PM
Post #11

UtterAccess Member
Posts: 28



Thanks, that works great.

Last question is formatting it to show "StartYear - EndYear" (i.e. 2002-2003) in the combo box.

Appreciate the help.
Go to the top of the page
 
+
fkegley
post Sep 26 2005, 04:11 PM
Post #12

UtterAccess VIP
Posts: 23,583
From: Mississippi



SELECT Year(Fiscal_Year.Start_Year) As SY, Year(Fiscal_Year.End_Year) As EY, Year(Fiscal_Year.Start_Year) & " - " & Year(Fiscal_Year.EndYear) As SYEY FROM Fiscal_Year

You'll probably want to hide the first two columns but use them instead of the displayed column. I no longer remember why you are doing this. LOL
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 18th May 2013 - 02:31 PM