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 Developer 20 Lessons    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Nested Recordset issue
Sami Shamma 
             
3 years ago
Good morning, friends
I am trying to populate two tables with recordsets. A header and detail. Table structure in the image below.
The records in the header table AssT are added correctly. My problem is that the key field AssID that I need for the detail table AssDetailT is not available to me.  My code below does not put the correct AssID in the detail table.
HELP!
Many thanks
DetailsPrivate Sub AssTBtn_Click()

    Dim db As Database
    Dim rsA As Recordset        'AssT
    Dim rsD As Recordset        'AssDetailT
    Dim rsO As Recordset        'AssOutcomeT
    Dim rsF As Recordset        'S_FacilityT
    Dim rsY As Recordset        'S_YearMonthT
    Dim rsR As Recordset        'S_ReligionT
    
    StatusBox = ""
    Set db = CurrentDb
    
    'Set rsF = db.OpenRecordset("S_FacilityT") ------------------------------------ for final code ***********
    Set rsF = db.OpenRecordset("SELECT * FROM S_FacilityT WHERE FacilityID= 1")
    While Not rsF.EOF
        Status rsF!FacilityName
        Set rsY = db.OpenRecordset("SELECT * FROM S_YearMonthT WHERE YMYear = ""2025""")
        While Not rsY.EOF
            'add record to AssT
            Set rsA = db.OpenRecordset("AssT")
            rsA.AddNew
            rsA!FacilityID = rsF!FacilityID
            rsA!YearMonthID = rsY!YearMonthID
            rsA.Update
            'add record to AssDetailT
            Set rsR = db.OpenRecordset("SELECT * FROM S_ReligionT WHERE IsReported")
            While Not rsR.EOF
                Set rsD = db.OpenRecordset("AssDetailT")
                rsD.AddNew
                rsD!AssID = rsA!AssID
                rsD!ReligionID = rsR!ReligionID
                rsD.Update
                Status "==== " & rsR!ReligionName
                rsR.MoveNext
            Wend
            rsY.MoveNext
        Wend
        rsF.MoveNext
    Wend
    rsA.Close
    rsD.Close
    rsO.Close
    rsR.Close
    rsY.Close
    rsF.Close
    db.Close
    Set rsD = Nothing
    Set rsA = Nothing
    Set rsO = Nothing
    Set rsR = Nothing
    Set rsY = Nothing
    Set rsF = Nothing
    Set db = Nothing
End Sub

Sami Shamma OP  @Reply  
             
3 years ago

Sami Shamma OP  @Reply  
             
3 years ago
I only need to add records with the fields indicated with red arrows. The rest is entered by the user.
Sami Shamma OP  @Reply  
             
3 years ago
I found a solution by inserting this code after my rsA.update
            rsA.Bookmark = rsA.LastModified
            ID = rsA!AssID

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

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/6/2026 9:55:48 AM. PLT: 1s