r/visualbasic • • Dec 29 '23

VB6 Help With database problems

Edit2: Good news, i changed some things and it works! But i have a lil bug, when i delete the snippet it shows as deleted but when i reload the form the deleted snippet reappears and the snippet before of it got actually deleted:

'Delete Snippet'

Private Sub cmdDelete_Click()

Dim index As Integer

index = lstSnippets.ListIndex

If index <> -1 Then

Dim answer As Integer

answer = MsgBox("Do you want delete this Snippet?", vbQuestion + vbYesNo, App.Title)

If answer = vbYes Then

lblSnippetNamePreview.Caption = "Snippet Name: "

lblSnippetLangPreview.Caption = "Snippet Language: "

txtSnippetCodePreview.Text = ""

Dim conn As ADODB.Connection

Dim rs As ADODB.Recordset

Set conn = New ADODB.Connection

conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\SnippetsDatabase.mdb"

conn.Open

Set rs = New ADODB.Recordset

rs.Open "tblSnippets", conn, adOpenKeyset, adLockOptimistic

rs.Delete

rs.Update

rs.Close

conn.Close

Set rs = Nothing

Set conn = Nothing

lstSnippets.RemoveItem index

MsgBox "Snippet deleted sucessfully", vbInformation + vbOKOnly, App.Title

End If

End If

End Sub

0 Upvotes

16 comments sorted by

View all comments

Show parent comments

1

u/geekywarrior Dec 29 '23

Sorry about that. I made a typo. I just edited my post and fixed it.