|
-
May 31st, 2008, 11:23 AM
#1
Thread Starter
Addicted Member
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
-
May 31st, 2008, 01:29 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jun 1st, 2008, 04:56 AM
#3
Re: Delete Problem!
Try
Code:
SQL = "DELETE FROM PAF WHERE thefieldname = '" & txtName.Text & "' "
MyData.Execute SQL
-
Jun 1st, 2008, 05:08 AM
#4
Re: Delete Problem!
 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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|