Table Design

Glennzo

Registered User.
Local time
Today, 11:43
Joined
Jan 24, 2003
Messages
22
Maybe someone can help get me started with a new project. I need to track names and addresses in a database. Also need to track donations for each person in the address database on a weekly basis. I'd like to relate the donation(s) to the date so that if I want to see what was donated during any given week I could. Would it also be possible, at the end of a session of entering data for 'this weeks' donations, to see a total of the figures that I just entered? Any thoughts on how to accomplish this task, assuming that I've presented myself with some semblence of clarity?

Thanks for taking time to read and consider.

Glenn
 
You need two tables, one for donors, one for donations. Hold a unique number as a primary key in the donor table and use this to link your donations to the donors (ie hold the donor ID in the donation table with a one to many relationship between the two tables). Hold the date against the donation and you can report out the data you want.
 
This is how I see these two tables:

tblDonors:
DonorId - AutoNumber - Primary Key
DonorName

tblDonations:
DonationId - AutoNumber - Primary Key
DonorId - Number - Linked to DonorID in tblDonors
DonationAmountWeek1
DonationAmountWeek2
DonationAmountWeek3
..........
DonationAmountWeek52

In order to hold the Date against the Donation the Date field will need to be in tblDonors?

Thanks for your time Neileg.
 
Glennzo said:

tblDonations:
DonationId - AutoNumber - Primary Key
DonorId - Number - Linked to DonorID in tblDonors
DonationAmountWeek1
DonationAmountWeek2
DonationAmountWeek3
..........
DonationAmountWeek52

Sorry, but aaarrgh!

Create a third table called tblWeeks and put all your weekly details in there - that way, for each each donation you can use the WeekID to determine which week the donation was.
 
I agree with Mile-o-Phile's aaarrgh!

But my approach would be slightly different:

tblDonors:
DonorId - AutoNumber - Primary Key
DonorName

tblDonations:
DonationId - AutoNumber - Primary Key
DonorId - Number - Linked to DonorID in tblDonors
DonationAmount -Currency
DonationDate -Date

You can report out which weeks these donations fall in. If you really need to tag the donations with a week number, add this as another field in the donations table.
 
Using neil's example you could take it further in saying that the weeknumber could be a calculated field so wouldn't need to be stored in the table.

When querying you could use a function to determine the week number from the date.

Code:
Function WeekNumber(ByVal dteYear As Date) As Integer
    
    On Error GoTo Err_WeekNumber
    
    ' Author: Mile-O-Phile
    ' Discussion: This function is designed to return the week number that a specific date appears in.
    '             Although, mahematically, there are generally 52 weeks in a year, the problem of leap
    '             years add a further day for consideration that would make a 53rd week that includes only
    '             one day. This is handled here by using the final day of a leap year as an 8th day in
    '             the 52nd week.

    ' Input(s): dteYear - the date value for which the user wishes to calculate the week number
    ' Process: check if year of chosen date is a leap year
    '          calculate week number
    ' Output(s): WeekNumber- the number, representing a week, that a date appears in a year (as an integer)
    
    Dim dteCount As Date, intCounter As Integer, booLeapYear As Boolean
    
    ' if year divided by 4 returns no remainder then the year is a leap year
    If Year(dteYear) Mod 4 = 0 Then booLeapYear = True
        
    ' get first date of year as a starting point
    dteCount = DateSerial(Year(dteYear), 1, 1)
          
    ' check if date chosen is first date of year
    If dteYear = dteCount Then
        WeekNumber = WeekNumber + 1
    Else
        ' check if the hosen date is within the latest date-check increment
        While dteYear > dteCount
            dteCount = dteCount + 7
            WeekNumber = WeekNumber + 1
            ' ensure that the leap year's extra day problem is resolved
            If WeekNumber = 53 And booLeapYear = True Then WeekNumber = 52
        Wend
    End If
    
Exit_WeekNumber:
    Exit Function

Err_WeekNumber:
    MsgBox Err.Number & Err.Description
    Resume Exit_WeekNumber
        
End Function
 
Yahoo! You folks are the greatest! I have to leave for work in a few minutes so I'll give these suggestions a go tonight. I'll add a third table for the weeks and make the necessary relations. A question though. I've been playing around with a similar scenario, created tables with relationships, a query and a form, but I cannot make changes to the dollar values in the weeks fields when I add a new record until I leave that record and come back to it. Only then is the week field editable. There must be a fairly obvious (to all but me) reason for this?

Glennzo
 

Users who are viewing this thread

Back
Top Bottom