9 Replies - 19951 Views - Last Post: 23 May 2012 - 06:53 AM Rate Topic: -----

#1 doty  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-May 12

Run-time error 3704 operation is not allowed the object is closed

Posted 19 May 2012 - 12:59 AM

Guys i need you help in this error
i use vb6 project with orcal DB and when i want to enter admin user name and password he give me this error

Run-time error 3704 operation is not allowed the object is closed

and when i click Debug he give me this code and the like is Yalow


pls i need u help guys

Dim cn As adodb.Connection
Dim cmd1 As String
Dim rs As adodb.Recordset
Dim rk As adodb.Recordset
Dim i, j As Integer

Dim sqlcmd, sqk, strsql, strname, str1, rate, a, b, c As String


Private Sub cmdCancel_Click()
main1.Show
Unload Me
End Sub

Private Sub cmdOK_Click()
Dim flag As Integer
flag = 0
[b]If rs.RecordCount <> 0 Then[/b]
rs.MoveFirst
Do While Not rs.EOF
If txtUserName.Text = rs.Fields(0) And txtPassword.Text = rs.Fields(1) Then
flag = 1
Exit Do
Else
rs.MoveNext
End If
Loop
If flag = 0 Then
MsgBox "INVALID USER"
txtUserName.Text = ""
txtPassword.Text = ""
Else
admn.Show
Unload Me
End If
Else
    MsgBox "NO RECORDS PRESENT !!!!"
End If
End Sub

Private Sub Form_Load()

On Error Resume Next
cmd1 = "Provider=MSDAORA.1;User ID=scott;password=tiger;Persist Security Info=False"

Set cn = New adodb.Connection
Set rs = New adodb.Recordset
With cn
 .ConnectionString = cmd1
.CursorLocation = adUseClient
 .Open
 End With
    rs.Open "SELECT * FROM admlog", cn, 2, 3
End Sub




Is This A Good Question/Topic? 0
  • +

Replies To: Run-time error 3704 operation is not allowed the object is closed

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Run-time error 3704 operation is not allowed the object is closed

Posted 19 May 2012 - 01:21 AM

As a guess, I would say your record set isn't getting populated.

Try putting a breakpoint in your form_load and step through the code to check that the connection is opened and/or the recordset is populated.

Try adding some "proper" error handling to it as well, On Error Resume Next is going to hide issues.
Was This Post Helpful? 0
  • +
  • -

#3 doty  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-May 12

Re: Run-time error 3704 operation is not allowed the object is closed

Posted 19 May 2012 - 01:26 AM

Thank you Maj but is not working
the issue is here

If rs.RecordCount <> 0 Then

Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Run-time error 3704 operation is not allowed the object is closed

Posted 19 May 2012 - 01:32 AM

I know where the issue is, you attempted to highlight in your first post.

So, did you do as I asked and stepped through the code in debug and checked that it's being opened and populated correctly?

This post has been edited by maj3091: 19 May 2012 - 01:33 AM

Was This Post Helpful? 0
  • +
  • -

#5 doty  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-May 12

Re: Run-time error 3704 operation is not allowed the object is closed

Posted 19 May 2012 - 01:41 AM

Thank you again dear Maj and i did like u tell me but nothing
but i will try again and i will let you know the result
I appreciate your efforts to help me
Was This Post Helpful? 0
  • +
  • -

#6 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Run-time error 3704 operation is not allowed the object is closed

Posted 19 May 2012 - 01:45 AM

Please explain "i did like u tell me but nothing"

Is the connection being opened?

If so, is the recordset being populated or not?
Was This Post Helpful? 0
  • +
  • -

#7 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: Run-time error 3704 operation is not allowed the object is closed

Posted 20 May 2012 - 11:10 AM

Doty,

Please don't PM me about a post that you have open. This is a sharing forum, so please keep things in the post.

On another note, PM-ing me with exactly the same code and question, when you haven't even replied to questions within the post, really isn't going to help matters.

Please answer the questions that I have asked and maybe we can move forward with your issue and help you resolve your problem.

This post has been edited by maj3091: 20 May 2012 - 11:10 AM

Was This Post Helpful? 0
  • +
  • -

#8 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Run-time error 3704 operation is not allowed the object is closed

Posted 21 May 2012 - 07:26 AM

I should observe that, although you have set your CursorType to dynamic and your LockType to optimistic, you in fact have a static cursor type and your lock type is read only. Any idea why that is?j

Next, vb6 doesn't allow you to comma-separate a bunch of declared variables and set their type at the end. You have to specifically set each one. So Dim i, j As Integer declares i as the default type of Variant (messy, inefficient) and j as an Integer. Clearly then your string declarations are even more of a mess. So, if you want to have two integers declared on the same line, you have to do this: Dim i as Integer, j as Integer

Next thing is, how do you know that the issue is where you say it is, when you suppress error handling in the form_load event? It's entirely possible (in fact extremely likely) that you fail to open the recordset due to an error and then blaze along happily unaware that your recordset failed to open until you quit suppressing error handling in your button event. Of course, if you had followed maj's advice, you'd already know this, but it seems that you'd rather tell him how nice of him it is to help you than to actually do what he asks.

It's like you're stuck in a room, trying to bang a hole in the wall with your forehead. We tell you here's the door, and you say thanks so much for trying to help, but I keep banging my head on the wall and the hole just won't open. And we say there's the door, and you say thanks very much, I don't understand why the hole won't open, I'm banging so hard and have such a hard head....

This post has been edited by BobRodes: 21 May 2012 - 07:27 AM

Was This Post Helpful? 0
  • +
  • -

#9 doty  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-May 12

Re: Run-time error 3704 operation is not allowed the object is closed

Posted 23 May 2012 - 04:02 AM

Thank you guys

I fix the error but I got new one it is


Compile Error: Block If without End If


BobRodes and Maj the door is where you are so thank you 4 help
Was This Post Helpful? 0
  • +
  • -

#10 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Run-time error 3704 operation is not allowed the object is closed

Posted 23 May 2012 - 06:53 AM

that means you have an if statement without an end if statement to go along with it. You left one out somewhere.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1