Results 1 to 4 of 4

Thread: Delete Problem!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    249

    Unhappy Delete Problem!

    okay, i have a problem with deleting items in my database...what happens is...lets say i have 3 items in my listbox and i decide to delete item # 2...it will delete it, but then when i restart my program it shows that it has deleted item #1 and item # 2 is still there what is happening? and how do i fix it to delete the correct/selected item?! please help! here is the code used:


    If MsgBox("Are you sure you want to delete " & txtName.Text & "?", vbQuestion + vbYesNo, "Delete Record") = vbYes Then
    Set MyData = OpenDatabase(App.Path + "\PAF.mdb")
    SQL = "SELECT * FROM PAF"
    Set MyRecord = MyData.OpenRecordset(SQL)
    MyRecord.Delete
    lstNames.RemoveItem lstNames.ListIndex

    Else
    Exit Sub
    End If

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Delete Problem!

    Are you doing this inside Access' VBA IDE?
    You should be executing a sqldelete statement instead.
    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
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Delete Problem!

    Try
    Code:
    SQL = "DELETE FROM PAF WHERE thefieldname = '" & txtName.Text & "' "
    MyData.Execute SQL

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Delete Problem!

    Quote Originally Posted by Hack
    Code:
    SQL = "DELETE FROM PAF WHERE thefieldname = '" & txtName.Text & "' "
    MyData.Execute SQL
    That wouldnt be preferred (may be invalid syntax too) if its in Access VBA which is why I was asking. For the possibility of it being Access VBA which is most possible as hes using DAO....
    Code:
    Application.CurrentDb.Connection.Execute "DELETE PAF.* FROM PAF WHERE thefieldname = '" & txtName.Text & "';", dbSeeChanges
    Now if this is a multiuser database then the last option could be changed to reflect your best needs. I set it to generate an error if another user is modifying one or more of the records to be deleted.
    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