Results 1 to 6 of 6

Thread: Delete all records in Jet data base from vb6 program

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    26

    Delete all records in Jet data base from vb6 program

    I need to delete all records in the Security table that relate to the investor umber. This is the code I used in my vb6 application.
    When I run this I get a dialog box which says "Operation is not allowed when object is closed."

    Even though this message appears, the table's records do delete.

    adoDelete.RecordSource = "DELETE FROM Security Where Investor_Number = " & txtInvestorNumber
    adoDelete.Refresh


    Any ideas on why this dialog shows or what I need to keep it from being displayed?

    Thank you,
    Dwight

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Are you using the ADO Data control?

    Where is your connection code? The recordset needs an open
    connection to execute the SQL code.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    26

    Property Page Dialog box

    Hey RobDog,
    I set the connection string of the ado using the property
    pages dialog box(right clicking the ado object).
    Then a change the recordsource through code, as required, as I listed above.

    My feeling is that even though calling the record source in this manner seems to work fine when adding, appending or deleting a single record, I must have to do it another way to delete multiple records using the "delete" method.

    Please help me with this if you can.
    I am new to vb6 and sql.

    Thanks so much,
    Dwight

  4. #4
    Junior Member
    Join Date
    May 2002
    Location
    Puerto Rico
    Posts
    29
    Try binding the ado control to a label on design, even if it won't show anything.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2004
    Posts
    26

    Did not work

    Hi geraf,
    Thanks for the effort, but it did not work.
    Any more suggestions?

    The idea was great, but binding the ado to a label did prevent the error message from appearing.
    As before though the table data relating to the filter(investor number) did delete.
    My only problem here is figuring out why the errror and what I need to do to correct it.

    Regards,
    Dwight

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Instead of trying to pass the delete sql use the control's .Delete
    method and apply a filter for the delete criteria.
    VB Code:
    1. Private Sub Command1_Click()
    2.     Adodc1.Recordset.Filter = "Investor_Number = '" & txtInvestorNumber & "'"
    3.     Adodc1.Recordset.Delete adAffectGroup
    4.     Adodc1.Recordset.UpdateBatch adAffectGroup
    5.     Adodc1.Recordset.Filter = adFilterNone
    6. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width