
How to delete data from Access Database in Visual Basic 6
Private Sub cmddelete_Click()
Dim CN As ADODB.Connection
Dim rs As ADODB.Recordset
Dim Y As Integer
On Error Resume Next
OpenDataFiles CN, rs, "YOURDATA.MDB", "SELECT * FROM MEMBER"
cmdsave.Enabled = True
If Not rs.BOF And rs.EOF Then
rs.MoveFirst
End If
Do While Not rs.EOF
If rs!customerno= txtcustomerno.Text Then
ans = MsgBox("Delete this Record?", vbYesNo, "Deletion Verification")
If ans = vbYes Then
rs.Delete
End If
End If
rs.MoveNext
Loop
'Call cleared 'this is optional based on your own code
CN.close
rs.close
OpenDataFiles CN, rs, "YOURDATA.MDB", "SELECT * FROM MEMBER order by LNAME"
If Not rs.BOF And rs.EOF Then
rs.MoveFirst
End If
Grid1.Refresh
Grid1.Rows = 1
Do While Not rs.EOF
' If rs!passbookno = txtpassbookno.Text Then
Grid1.AddItem rs!customerno 'you can specify you recordset here, if you want to update some of your Grids if you have one.
End If
rs.MoveNext
Loop
Call cleared 'this is optional based on your own code.
End Sub