6 Replies - 14292 Views - Last Post: 30 August 2010 - 06:34 PM Rate Topic: -----

#1 phreanz_44  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-March 10

Error 3704 Operation is not allowed when object is closed

Posted 29 August 2010 - 03:08 AM

'here is what i have:

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....

'tnx

This post has been edited by phreanz_44: 30 August 2010 - 12:30 AM
Reason for edit:: Added code tags.


Is This A Good Question/Topic? 0
  • +

Replies To: Error 3704 Operation is not allowed when object is closed

#2 Ahmedn1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 23
  • View blog
  • Posts: 556
  • Joined: 04-August 09

Re: Error 3704 Operation is not allowed when object is closed

Posted 29 August 2010 - 04:46 AM

I think this error occurs where you open a connection or recordset

so do the check on them both

If rs.State = 1 Then 
rs.Close

If cn.State = 1 Then
cn.Close




check where the error occurs and apply this condition
Was This Post Helpful? 0
  • +
  • -

#3 parbipin  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 95
  • Joined: 23-August 10

Re: Error 3704 Operation is not allowed when object is closed

Posted 29 August 2010 - 12:49 PM

When (On which Line) do you get this Error. Is it when you refresh datagrid, close connection???
Was This Post Helpful? 0
  • +
  • -

#4 phreanz_44  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-March 10

Re: Error 3704 Operation is not allowed when object is closed

Posted 30 August 2010 - 12:36 AM

ii got problem on the line:
Datagrid1.Refresh

i tried to comment that part and it doesn't give any error....
i tried to use this line so that after i deleted information, datagrid would be updated in an instant without closing and starting the program but it gave me this error....
Was This Post Helpful? 0
  • +
  • -

#5 Guest_phreanz_44*


Reputation:

Re: Error 3704 Operation is not allowed when object is closed

Posted 30 August 2010 - 01:54 AM

View Postparbipin, on 29 August 2010 - 11:49 AM, said:

When (On which Line) do you get this Error. Is it when you refresh datagrid, close connection???


i got problem on the line:
Datagrid1.Refresh

i tried to comment that part and it doesn't give any error....
i tried to use this line so that after i deleted information, datagrid would be updated in an instant without closing and starting the program but it gave me this error....
Was This Post Helpful? 0

#6 parbipin  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 95
  • Joined: 23-August 10

Re: Error 3704 Operation is not allowed when object is closed

Posted 30 August 2010 - 05:26 AM

Youa re using a delete operation in ADODC and then trying to pull data in Datagrid; This seems to be the root of the problem.

Set Datagrid1.DataSource = rs

this should do your job;


have a lok at this;

My linkhttp://www.vbtutor.net/lesson26.html


*Added a link

This post has been edited by parbipin: 30 August 2010 - 05:28 AM

Was This Post Helpful? 0
  • +
  • -

#7 phreanz_44  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-March 10

Re: Error 3704 Operation is not allowed when object is closed

Posted 30 August 2010 - 06:34 PM

i got the solution,

Private Sub cmdDelete_Click()
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
MsgBox "Deleted!", vbInformation, "deleted!"
Adodc1.Recordset.Delete
End If
errr:
MsgBox "Error occured! " & Error, vbExclamation, "Error" & Err.Number
disconnect
End Sub

thanks to all your help guys!!!! have a nice day!!!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1