connect On Error GoTo errr: rs.Open "select * from NMCDatabase where StudentNumber = '" & DataGrid1 & "'", cn, 3, 3 If MsgBox("Are you sure you want to delete this " & DataGrid1.Text & " and all related records?", vbQuestion + vbYesNo, "Delete?") = vbYes Then Adodc1.RecordSource = "delete from NMCDatabase where StudentNumber = '" & DataGrid1.Text & "'" Adodc1.CommandType = adCmdText MsgBox "Deleted!", vbInformation, "deleted!" Adodc1.Refresh DataGrid1.Refresh End If If rs.State = 1 Then cn.Close End If Exit Sub If rs.State = 1 Then cn.Close End If errr: MsgBox "Error occured! " & Error, vbExclamation, "Error" & Err.Number If rs.State = 1 Then cn.Close End If End Sub
this is what i have on my module:
Public cn As New ADODB.Connection Public rs As New ADODB.Recordset Public Sub connect() cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " & App.Path & "\StudentInfoSystem_db.mdb" cn.CursorLocation = adUseClient End Sub Public Sub disconnect() If rs.State = 1 Then cn.Close End If End Sub
'my only problem here is that the datagrid is not refreshing everytime i delete some record after clicking the 'command button (cmdDelete)
'it has error that says : operation not allowed when obect is closed, error 3704....
This post has been edited by phreanz_44: 30 August 2010 - 12:30 AM
Reason for edit:: Added code tags.