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 Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Recordset update subform
Kim Nielsen 
      
3 years ago
Hello There;
I have been working on this the last 3 days, and i can not seem to find out why this is not doing what I want it too. I hope someone can look this over and maybe help me understand why not. I am trying to update a subform Record IDs when the main form record ID gets updated. This is so all the records with the old ID will again match the updated record id on the main form.

This is the code i am working with right now. I am hopeful someone can direct me on the right path?


code
Private Sub AgencyName_AfterUpdate()
    Dim newRecordID As Integer
    Dim subformRS As Recordset
    Dim Response As Integer
    
    Response = MsgBox("You are about to change the Record ID to the new selection, do you wish to continue?", vbYesNo + vbQuestion, "Confirm Change")
    If Response = vbYes Then
        Me.AgencyCode = Me.AgencyName.Column(0)
        Me.FDRecordID = Me.AgencyCode & "-" & Me.RecYear & "-" & Me.SeriesNum 'this creates a new record ID with the new 2 digit code of agency and keeps same date
        GoTo NewRecords
    
    ElseIf Response = vbNo Then
        Undo
        btnClose.SetFocus
        Form_Current
    End If
    Exit Sub

NewRecords: ' here we want to take the new record ID generated and replace all the old corresponding subform record ids to the new one

            newRecordID = Forms!DeptEditFillRecordF!FDRecordID.Value
            
            Set subformRS = Forms!DeptEditFillRecordF!CylFillsListSF.Form.RecordsetClone
            subformRS.MoveFirst
            Do Until subformRS.EOF
                If subformRS!FDRecID = FDRecID Then
                    subformRS.Edit
                    subformRS!FDRecID = newRecordID
                    subformRS.Update
                End If
                subformRS.MoveNext
                Loop

                Forms!DeptEditFillRecordF!CylFillsListSF.Form.Requery
            
End Sub
Kevin Robertson  @Reply  
          
3 years ago
You have an Exit Sub which is preventing the bottom block of code from running.
Kim Nielsen OP  @Reply  
      
3 years ago

Kim Nielsen OP  @Reply  
      
3 years ago
Kevin;

This popped up as an error, everything is spelled correctly but can not understand what this error is.

Thanks
Kim Nielsen OP  @Reply  
      
3 years ago

Kim Nielsen OP  @Reply  
      
3 years ago
Kevin this is the form and subform. The aferupdate is tied to the drop down, the Colum 0 goes into a hidden field and the main record id is updated, the problem is getting the record id updated in the subform as well. Feel like i am looping like  an uncontrolled recordset.

Thanks
Kevin Robertson  @Reply  
          
3 years ago
What was the Error message?
Kim Nielsen OP  @Reply  
      
3 years ago
Just stops in the vba code (Image above) and highlights the one line of code and stops. It does not move unless i stop the code. Very odd.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer 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/6/2026 11:21:48 AM. PLT: 1s