Question

I have datagrid using adodb (not adodc) when user double click record from The datagrid, record will appear on the label. but when user close the form. there is an error

Ms Datagrid control / The Current row isn't avaiable

I don't know what is wrong, I have already close the recordset while form unload

this is my code

Dim myrecordset As New ADODB.Recordset

Private Sub dtgrid_DblClick()
Label9.Caption = ""
Label9.Caption = dtgrid.Columns(0)
End Sub

Private Sub Form_Load()
Call ConnectDB
With myrecordset
.ActiveConnection = con
'.LockType = adLockReadOnly
.CursorType = adOpenForwardOnly
.CursorLocation = adUseClient
.Open "SELECT * FROM Foo "
End With
Set dtgrid.DataSource = myrecordset
End Sub

Private Sub Form_Unload(Cancel As Integer)
myrecordset.close
set myrecordset = nothing
Call CloseDB
End Sub

this is from module

Public function CloseDB
    Set CMD = Nothing 'adodb command
    con.Close
    Set con = Nothing 'adodb connection
end sub
Was it helpful?

Solution

Probably because you closed the recordset and the datasource still is pointing to it. Try setting the DataSource property to nothing before closing the recordset.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top