473,385 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Update query, dcount, two tables

32
I am trying to add a functionality into a db I use for my checkbook that will help me plan for and save money for future large expenses. Into a table called tblFutureTransactions I want to enter records for upcoming large expenses, the dollar amount needed, the date the money is needed, and the date I want to start saving. Then I want the db to automatically figure and deduct from my balance an amount of money from each paycheck to save for the future expense. To do that I need to be able to find how many paydays fall within those dates (StartSaving and EndSaving).

I have a table of future expenses:
tblFutureTransactions it has these fields:
StartSaving (date/time)
EndSaving (date/time)
NumberOfPaydaysDuringSavingPeriod (number)

And a table of the dates of my paydays (every other Wednesday) for the next year:
tblPaydayDates it has only two fields
PaydaysPriKey (primary key auto-numbered)
UpcomingPaydayDates (date/time)

So I am trying to run an update query where the "update to" field is a dcount statement that counts records in tblPaydayDates using date range criteria from tblFutureTransactions. The dcount statement doesn't work, but you can probably see what I'm trying to do:
DCount("PaydaysPriKey","tblPaydayDates",tblPaydayD ates.UpcomingPaydayDates Between tblFutureTransactions.StartSaving And tblFutureTransactions.EndSaving)

I'm trying to use the update query (and the dcount inside it) to update tblFutureTransactions.NumberOfPaydaysDuringSavingP eriod with the count of how many of the records in tblPaydayDates fall between tblFutureTransactions.StartDate and tblFutureTransactions.EndDate.
Oct 4 '07 #1
3 4842
NeoPa
32,556 Expert Mod 16PB
Firstly, an UPDATE query can only work if the underlying query is updatable.
A SELECT query including a DCount() call would NOT be so.
You need to look at an UPDATE query that progressively increments the count for every valid date it comes across. This means that an individual record may be updated many times, but that's the way to get it to work.
Oct 4 '07 #2
ringer
32
Thanks for the reply NeoPa, but it's working now. For future searchers, I'll post the entire query to show the dcount statement in context:
Expand|Select|Wrap|Line Numbers
  1. UPDATE tblFutureTransactions SET tblFutureTransactions.NumberOfPaydaysDuringSavingPeriod = DCount("*","tblpaydaydates","upcomingpaydaydates Between #" & Format(StartSaving, "mm\/dd\/yyyy") & "# And #" & Format(EndSaving, "mm\/dd\/yyyy") & "#");
Credit for the solution goes to Ken Snell at the MS Community boards for fixing the dcount syntax.
Oct 5 '07 #3
NeoPa
32,556 Expert Mod 16PB
OOoops.
Sorry about that. I'll have to review some of mine in that new light then. Thanks for this.
Oct 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default...
3
by: rrh | last post by:
I am trying to update a field in one table with data from another table. The problem I'm running into is I need to base the update on a range of data in the 2nd table. Table 1 has: date field...
2
by: mhodkin | last post by:
I created a query in which I have grouped data by City. I wish to calculate the percent of each value, e.g. City/(Total count of all Cities), in tbe next column of the query. I can't seem to...
3
by: BerkshireGuy | last post by:
I am having difficulty with using the Dcount function. I am trying to return the number of records from qryIndividualFeedbackDetail where the TimelyManner field is set to 4. So, in the new...
9
by: DP | last post by:
hi., i've got 3 tables, customer, film and filmrental. i've got a customer form, with a sub form at the bottom, which is a film rental subform. i've created an update query, which when a...
2
by: ChasW | last post by:
Greetings, I have a form that uses a query as its record source. In the form I have a text box that uses this as its control source: =DCount("", "qry_Search_by_Name") The DCount function...
1
by: Gilz | last post by:
Hi I was wondering if anyone could help i have picked this database up from a designer who has now left the company. The code is a couple of years old. On click of a button it open a...
11
tuxalot
by: tuxalot | last post by:
The easy way is to put cancel = True in the On No Data event of the report. But why replicate code across all reports that way? My app selects reports from a listbox, so I would prefer to check the...
16
by: OldBirdman | last post by:
I have tables to contain the names of the birds of the world. tGN - Genus scientific (Latin) names Key (PK) autonum Ptr->FA (FK) pointer to key in table=FA Not used in this problem...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.