It is called RaceDate.@arnelgp
There is no field called Date?
It is called RaceDate.@arnelgp
There is no field called Date?
In my limited experience with Access, I learned that Auto Numbers were "essential" to a database. I don't necessarily agree with that info today, I would say that the Primary Key for this database is a composite of RaceDate and RaceTime. Any duplicates to that are where there is more than one bet in the same race, which happens often but not always.In 25+ years working with various database projects, I learned the hard way that relying on AutoNumbers for sequencing is a dangerous practice on which to build a mission critical application.
I would say that the Primary Key for this database is a composite of RaceDate and RaceTime. Any duplicates to that are where there is more than one bet in the same race, which happens often but not always.
No, that is also incorrect. A good primary key is essential. Autonumbers will always make good primary keys, but are not essential or the only good choice for PKs. A PK needs to be unique, non-changing (or at least rarely), simple (no special characters, spaces, etc.), and known at the time the record is entered.2. In my limited experience with Access, I learned that Auto Numbers were "essential" to a database.
Out of curiosity what part do you disagree with? I can again assure you are mistaken. The information I presented is accurate.I don't necessarily agree with that info today,
Did you even read what I wrote? If the assumptions I presented are possibly true, then query1 will fail. If and only if records are entered into the database always in the correct order will it work. Is that the case? You never are going to miss a single entry and have to go back and enter it?So the issue with RunningTotal is now resolved by Query 1
SELECT transaction.*,
(SELECT SUM(winlose)
FROM transaction AS T
WHERE ( T.racedate + T.racetime ) <= (
transaction.racedate + transaction.racetime )
AND T.transid <= transaction.transid) AS RunningTotal
FROM [transaction]
ORDER BY transaction.racedate,
transaction.racetime, transID;
Two different things.In my limited experience with Access, I learned that Auto Numbers were "essential" to a database. I don't necessarily agree with that info today, I would say that the Primary Key for this database is a composite of RaceDate and RaceTime. Any duplicates to that are where there is more than one bet in the same race, which happens often but not always.
Hm. As MajP pointed out, you can't actually enforce a unique combination of RaceDate and RaceTime, so that isn't even an option. You could still create a composite index, though, which would be non-unique, for sorting.Two different things.
AutoNumbers are good for one thing only. They provide unique values that make ideal Primary Keys.
The other issue is being able to create a unique index on two or more fields. RaceDate and RaceTime would be a candidate for that index.
You could enforce a unique combination of RaceDate and RaceTime on those two fields without having to use it as the Primary Key.
Many a lively debate has been sparked over the choice of Surrogate keys (i.e. non-meaningful values such as those provided by the AutoNumber) or Natural Keys (i.e. your two field composite RaceDate and RaceTime). You can make either one the Primary Key in a table.
I am firmly in the surrogate key camp, but many highly skilled database developers prefer Natural Keys. Your call.
The important thing here is that your need is for a reliable way to sort records by date and time. That's not what a Surrogate Key like an AutoNumber is good at. However, that doesn't mean abandoning the AutoNumber, which is --in my opinion-- superior in other ways.
However, I do know the solution. That is a properly normalized database.The RaceDate and the RaceTime are important to the order and I need to have a possibility for multiple bets in one race which thwarts the idea of these two fields forming a composite key. I'm not sure what the final solution is.
MeetingID | RaceDate | MeetingLocation |
---|---|---|
1 | 12/16/2023 | Caulfield |
2 | 12/16/2023 | Randwick |
3 | 12/23/2023 | Moonee Valley |
4 | 12/23/2023 | Randwick |
5 | 1/6/2024 | Geelong |
6 | 1/6/2024 | Randwick |
7 | 1/13/2024 | Flemington |
8 | 1/13/2024 | Rosehill |
RaceID | MeetingID_FK | RaceTime | RaceNum | Distance |
---|---|---|---|---|
1 | 1 | 1:20:00 PM | 3 | 1600 |
2 | 1 | 1:55:00 PM | 4 | 1400 |
3 | 1 | 2:30:00 PM | 5 | 1200 |
4 | 1 | 4:20:00 PM | 8 | 1400 |
5 | 1 | 5:00:00 PM | 9 | 1400 |
6 | 2 | 1:05:00 PM | 2 | 1600 |
7 | 2 | 1:40:00 PM | 3 | 1400 |
8 | 2 | 3:25:00 PM | 6 | 1100 |
9 | 2 | 4:00:00 PM | 7 | 1600 |
10 | 2 | 4:40:00 PM | 8 | 1400 |
TransID | RaceID_FK | Tab | HorseName | Rating | Plus1 | Plus2 | Clarity | Stake | Result | Dividend | WinLose |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | 28 | 4 | Tympanist | 1 | o | Avg | $20.00 | 2nd | | ($20.00) | |
2 | 1 | 5 | Fullproof | 1 | o | Avg | $20.00 | Unp | | ($20.00) | |
3 | 29 | 10 | Zouphoria | 1 | oo | Avg | $20.00 | Won | $2.60 | $32.00 | |
4 | 23 | 8 | Running By | 1 | oo | Avg | $20.00 | Won | $1.70 | $14.00 | |
5 | 3 | 1 | Is It Me | 1 | oo | Avg | $20.00 | Won | $2.90 | $38.00 | |
6 | 19 | 10 | Boston Rocks | 1 | o | Avg | $20.00 | Won | $2.70 | $34.00 | |
7 | 30 | 11 | Grebeni | 1 | oo | Avg | $20.00 | Won | $4.50 | $70.00 | |
8 | 15 | 8 | He's Handsome | 1 | o | Avg | $20.00 | Unp | | ($20.00) | |
9 | 31 | 8 | Plundering | 1 | o | Avg | $20.00 | 3rd | | ($20.00) | |
10 | 46 | 9 | Dubai Poet | 1 | oo | Good | $20.00 | 3rd | | ($20.00) |
However, I do know the solution. That is a properly normalized database.
You need the following tables
tblMeetings
MeetingID PK autonumber
tblRaces
RaceID PK autonumber
MeetingID_FK 'relates to meetings
tblRaceTransactions
TransID PK autonumber
RaceID_FK ' relates to a race
tblMeetings tblMeetings
tblRaces (top 10)
MeetingID RaceDate MeetingLocation 1 12/16/2023Caulfield 2 12/16/2023Randwick 3 12/23/2023Moonee Valley 4 12/23/2023Randwick 5 1/6/2024Geelong 6 1/6/2024Randwick 7 1/13/2024Flemington 8 1/13/2024Rosehill
tblRaces tblRaces
tblRaceTransactions
RaceID MeetingID_FK RaceTime RaceNum Distance 1 1 1:20:00 PM3 1600 2 1 1:55:00 PM4 1400 3 1 2:30:00 PM5 1200 4 1 4:20:00 PM8 1400 5 1 5:00:00 PM9 1400 6 2 1:05:00 PM2 1600 7 2 1:40:00 PM3 1400 8 2 3:25:00 PM6 1100 9 2 4:00:00 PM7 1600 10 2 4:40:00 PM8 1400
tblRaceTransactions tblRaceTransactions (top 10)
View attachment 111954
TransID RaceID_FK Tab HorseName Rating Plus1 Plus2 Clarity Stake Result Dividend WinLose 1 284 Tympanist 1 o Avg $20.002nd ($20.00) 2 15 Fullproof 1 o Avg $20.00Unp ($20.00) 3 2910 Zouphoria 1 oo Avg $20.00Won $2.60 $32.00 4 238 Running By 1 oo Avg $20.00Won $1.70 $14.00 5 31 Is It Me 1 oo Avg $20.00Won $2.90 $38.00 6 1910 Boston Rocks 1 o Avg $20.00Won $2.70 $34.00 7 3011 Grebeni 1 oo Avg $20.00Won $4.50 $70.00 8 158 He's Handsome 1 o Avg $20.00Unp ($20.00) 9 318 Plundering 1 o Avg $20.003rd ($20.00) 10 469 Dubai Poet 1 oo Good $20.003rd ($20.00)
Now that it is properly normalized you can build a form
View attachment 111957
At the top you add Meetings
Below that you add races
Whatever race you are clicked on you add transactions
(Notice you can have 1 or mor transactions for a race )
(you might want to add the raceID_FK on the transaction subform so you can easily see what race number it is)
The second tab shows (no edit) all the transactions for that meeting
Give it a try to see if works.
I've changed the qryRunningTotals_MajP query with tblRaceTransactions. I'm running it now and its giving me the "Add Parameter"msg for T.RaceTime, I'm not sure what that is about, can you have a look at it?Thank you MajP I'm knocked outt! In a good way. You've put a lot of time and effort into this it looks great!
One minor thing was I ran the query "qryRunningTotals_MajP" and it gave an error about could find transaction table. Looking at the SQL it has the name "Transaction" but I think it could be tblRaceTransactions instead. I can change the field name in the SQL. Does Access have a find and replace feature? I can do it by hand there's not many.
It looks great. I will have to implement all this in the actual database, I can probably import everything into the new database. You've done a great job. Thanks very much. I'll go and have a play with it.
Done.Delete that query. That is old. The new query is called qryAllData_WithRunningSum
The form part is not that important, it is getting a correct table structure. You need to verify it makes sense for what you are doing. I believe it is correct. Once you build the tables and logic you can build a form like this pretty quickly using the wizards.you've put a lot of time and effort into this it looks great!
Maybe. Is this different from a racetime in the Race table?The RaceTime field is important in that it tells me what is the Next race of interest. Did that have to go from the Meetings table?
Maybe. Is this different from a racetime in the Race table?
My guess was that a meeting represents a Race Day. A Race Day would be a location and given date for a set of races. The races are then built in the race table. Races have racetime.
If that is not correct, then what is a meeting and how does that relate to the races on that day?
Clearly the forms are all linked, but I added some conditional formatting to show the selected race. People are not as familiar looking at synched continuous subforms.
At Moonee Value on 12/23 there races 1,4,6,7,8,10
In race 10 there are two transactions for Veloce Carro, and Private Jumbo
View attachment 111964