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 
SQL Statement Delete
Simon Levesque 
     
3 years ago
Hello! I have a continuous form as a subform that has a junction table as control source. On the parent form that is linked to this junction table, I want to prevent orphan records with the code provided by Richard. It works fine for multiple other forms in my Db but this one is a tricky one. Ive tried this code but doesn't seem to delete anything because there are records in the "child" table. Any ideas?

Private Sub Form_Unload(Cancel As Integer)
    If IsNull(EffectifSR) And Not IsNull(EffectifID) Then
        If Not IsNull(Form.SubF_OF_F!ID) Then
            Dim rs As Recordset
            Set rs = Me.SubF_OF_F.Form.RecordsetClone
            rs.MoveFirst
            Do Until rs.EOF
                DoCmd.SetWarnings False
                DoCmd.RunSQL "DELETE FROM Jonction_OF_T WHERE ID=" & rs!ID
                DoCmd.SetWarnings True
            
                rs.MoveNext
            Loop

            Set rs = Nothing
        End If
        DoCmd.SetWarnings False
        DoCmd.RunSQL "DELETE FROM EffectifSR_T WHERE EffectifID=" & EffectifID
        DoCmd.SetWarnings True
    End If
End Sub
Scott Axton  @Reply  
        
3 years ago
First check your spelling.
       DoCmd.RunSQL "DELETE FROM Jonction_OF_T WHERE ID=" & rs!ID
Is that line correct?

Need additional information.  Are you getting error messages?
If so:
What is the message?
What is the code that is highlighted in yellow after you get the error message?
Scott Axton  @Reply  
        
3 years ago
I suggest remming out any DoCmd.SetWarnings False until after you have tested your program and are satisfied with the results.    
That can mask problems you would otherwise have caught.

Please tell me you are not doing your development on a live database.  You are hopefully (should be) developing on a copy prior to implementation.
Simon Levesque OP  @Reply  
     
3 years ago
Not a live one, 6 months from there! Dont know what to think but everything works fine now'.Weird. Thank you for your time

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 1:50:58 PM. PLT: 1s