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 
Update field on close or open
David Buller 
   
4 years ago
Hi, I have a db with a mix of active & inactive members. Active members are defined as those that have been in contact with me within last 60-days. So some will inevitably go from being active to inactive as time goes by if no contact is made. What is best way for me to automatically scan the db so that the Active field in the main form (currently a tickbox) is unselected (ie marked as Inactive) whenever the db is either fired up or closed down. Any help/comment appreciated.
Adam Schwanz  @Reply  
           
4 years ago
Use a recordset, I think they start in Access Developer 16
Kevin Yip  @Reply  
     
4 years ago
You may use a calculated field for your checkbox.  Is the last contact date in the same table?  Your checkbox box could have a control source like this one:

     =IIf((Date()-[LastContactDate])) > 60, False, True)
     (Note: if [LastContactDate] could be Null, you need to modify the above accordingly.)

A calculated field is evaluated automatically for all the rows all the time, so there is no need to wait for a form to open or close.  Seems like this is what you need, because you don't do this for this one time, but for all time going forward, whenever you look at the data.

If [LastContactDate] is in another table, you may use DLookup() in the expression for the calculated field.  But DLookup() may slow things down in a calculated field because, as I said, all the rows are evaluated all the time.
Scott Axton  @Reply  
        
4 years ago
If you are not storing the last contact date I would recommend doing so.  It kind of sounds like you just have  the check field.  
Check out the Contacts video and the Reminder Popup video for some ideas.
David Buller OP  @Reply  
   
4 years ago
Thanks, I have 2 data tables for clients visiting our local foodbank; a ClientsTbl & a ClientVisitsTbl. The Active field is in the ClientsTbl whilst the ClientVisitsTbl carries a list of the dates that all clients have been in contact. I have made some progress with doing what i need using a recordset but am falling down in it with picking out which clients are Active vs Inactive. My definition of an Inactive client is one that hasn't been in contact within the last 60 days. I have the following:

Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
    Set db = CurrentDb()
    Set rs1 = db.OpenRecordset("ClientsTbl")
    Set rs2 = db.OpenRecordset("ClientVisitsTbl")
       rs1.MoveFirst
       Do Until rs1.EOF
       If rs1!Active = -1 And Date - rs2!VisitDate > 60 Then
         rs1.Edit
         rs1!Active = 0
         rs1.Update
       End If
       rs1.MoveNext
   Loop
End Sub

If I delete the "And Date - rs2!VisitDate > 60" part of this routine then it will run & set all Active clients to Inactive , i.e. value -1 in a checkbox. However, I cannot seem to configure the "And Date - rs2!VisitDate > 60" section to pickup those clients that are still Active, i.e. they have contacted me within the last 60 days. I'm just not proficient enough with VBA I'm afraid, more used to Excel. Do I need an ELSE statement as well as IF - AND or what? Also, as I have a list of visit dates for each client how do I set up the routine to take its VisitDate calculation (for the within 60days criterion) from their most recent visit? Any help much appreciated
Kevin Robertson  @Reply  
          
4 years ago
Try it like this:
rs2!VisitDate > Date - 60
David Buller OP  @Reply  
   
4 years ago
rs2!VisitDate > Date - 60. No, that doesn't seem to do it
Adam Schwanz  @Reply  
           
4 years ago
It doesn't know what rs2!VisitDate is, you don't set what record it is anywhere. I would just take rs2 out all togethor.

Try this, replace the ID section with your unique field if different

Date - DLOOKUP("VisitDate","ClientVisitsTbl","ID=" & rs1!ID) > 60
David Buller OP  @Reply  
   
4 years ago
Many thanks Adam, following is working fine now, just had to change your DLOOKUP to DMAX. Excellent.

Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset

    Set db = CurrentDb()
    Set rs1 = db.OpenRecordset("ClientsTbl")
    Set rs2 = db.OpenRecordset("ClientVisitsTbl")
    
       rs1.MoveFirst
            Do Until rs1.EOF
       If rs1!Active = -1 And Date - DMax("VisitDate", "ClientVisitsTbl", "ClientID=" & rs1!ClientID) > 60 Then
      
         rs1.Edit
         rs1!Active = 0
         rs1.Update
      
       End If
       rs1.MoveNext
   Loop

End Sub

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: 6/22/2026 3:14:58 PM. PLT: 1s