Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
DCount
Andrew Cleary 
   
5 years ago
I am trying to use DCount to count the number of records in a set of queries and send it to a table using an append query.  Am I doing this right or is there a better way...
Alex Hedley  @Reply  
           
5 years ago
Is this to store historic data?
Scott Axton  @Reply  
        
5 years ago
Andrew -
Your question doesn't really describe what you are trying to do very well.  The short answer is no, DCount is probably NOT what you need to use.
DCount answers the question "how many?"  For example if I wanted a COUNT of customers that lived in Colorado.
Andrew Cleary OP  @Reply  
   
5 years ago
Yes this is for historical data.  I want the database to store how many of an item we had in a certain area of our building when we update the database.
Scott Axton  @Reply  
        
5 years ago
If you are just wanting a record of what was there at a given point in time, yes you could use DCount to append to the history table.  Such as:
3/23/2021    Bay1  5 gold bars
4/01/2021    Bay1  6 gold bars
5/15/2021    Bay1  4 gold bars
Richard Rost  @Reply  
          
5 years ago
The bottom line is YES it can be done, but it all depends on how you have your tables set up, and how much VBA/SQL you know. I see you're only a Beginner user, so I'm not sure how much of this you will understand without further training, but the easiest way to do this in VBA would be (this is pseudocode)...

X = DCount(Records in Query1)
X = X + DCount(Records in Query2)
etc.
DoCmd.RunSQL "INSERT INTO ResultTable..."


So yes. Pretty much ANYTHING can be done. All depends on the specifics. See DCount, INSERT INTO, Intro to VBA
Andrew Cleary OP  @Reply  
   
5 years ago
Thanks Richard I will check out the links you have provided.  I have a lot of ideas in my head it is just getting those ideas into my database.  Your video's have been awesome and are my go to when trying out something new!
Richard Rost  @Reply  
          
5 years ago
Glad you like them. :)
Andrew Cleary OP  @Reply  
   
5 years ago
I finally got it working thanks for the feedback and suggestions.  This is the code that I ended up using.

If Me.Dirty = True Then Me.Dirty = False 'Save any unsaved data
    Set db = CurrentDb
    Set rs = db.OpenRecordset("AreaHistoryT")
    With rs
        .AddNew
        ![DateTime] = Now()
        ![CountofCarts] = DCount("*", "[IpccCartAge_Q]")
        ![CountofCCS] = DCount("*", "[IpccCcsAge_8_Q]")
        ![CountofFluid] = DCount("*", "[IpccFluidAge_20_Q]")
        ![CountofZone1] = DCount("*", "[Qry_OB_Dwell_Zone1_10]")
        ![CountofZone2] = DCount("*", "[Qry_OB_Dwell_Zone2_10]")
        ![CountofZone3] = DCount("*", "[Qry_OB_Dwell_Zone3_10]")
        ![CountofZone4] = DCount("*", "[Qry_OB_Dwell_Zone4_10]")
        ![CountofST] = DCount("*", "[Qry_OB_Dwell_ST]", "[Dwell Time] >2")
        ![COuntofPB] = DCount("*", "[Qry_OB_Dwell_PB2hr]")
        ![CountofPTSiLPN] = DCount("*", "[iLPN_PTS8_Q]")
        ![COuntofBPiLPN] = DCount("*", "[Qry_iLPN_BP8]")
        ![COuntofOthe
Andrew Cleary OP  @Reply  
   
5 years ago
.Update
    End With
    'If you are doing this through a form which is bound to t_Clients,
    'then don't forget you need to requery it to see this addition
    'Next 2 lines are optional depending on the above
    Me.Requery
Richard Rost  @Reply  
          
5 years ago
Looks good. Do you see now why I tell people NOT to use spaces in their table and field names? :)
Andrew Cleary OP  @Reply  
   
5 years ago
My Naming Convention has changed thanks to you mid Development...
Richard Rost  @Reply  
          
5 years ago
Yeah that can be trouble too. LOL. The most important thing is to just remain consistent.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/2/2026 8:41:56 AM. PLT: 1s