Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error: Object invalid or no longer set?? Can you help?

Status
Not open for further replies.

jasonmac

Programmer
Nov 14, 2002
175
US
Hello everyone. I'm using access '97 and I'm getting an error that I don't know how to correct. I have a form with a subform and as I go through the records and come to a record that has data in the subform I get this error.

"Object invalid or no longer set." The error seems to be in the on current event. Here it is:

Code:
Private Sub Form_Current()
Dim recClone As Recordset
    If Me.NewRecord Then
        cmdNewRecord.Enabled = False
        cmdAdd.Enabled = True
        cmdCloseForm.Visible = False
        Me.cmdCancel.Visible = True
    Else
        cmdNewRecord.Enabled = True
        cmdAdd.Enabled = False 
    End If
    
    If Me.NewRecord Then
        cmdFirstRecord.Enabled = False
        cmdNext.Enabled = False
        cmdBack.Enabled = False
        cmdLastRecord.Enabled = False 
        Exit Sub
    End If

'THIS IS WHERE ACCESS  SAYS THE ERROR IS
'Me.Recordsetclone = <object invalid or no longer set>
    Set recClone = Me.RecordsetClone

    If recClone.RecordCount = 0 Then  
         cmdFirstRecord.Enabled = False
         cmdNext.Enabled = False
         cmdBack.Enabled = False
         cmdLastRecord.Enabled = False
    Else
         recClone.Bookmark = Me.Bookmark
         recClone.MovePrevious
         cmdFirstRecord.Enabled = Not recClone.BOF
         cmdBack.Enabled = Not recClone.BOF
         recClone.MoveNext
         recClone.MoveNext
         cmdLastRecord.Enabled = Not recClone.EOF
         cmdNext.Enabled = Not recClone.EOF
         recClone.MovePrevious
    End If
         Set recClone = Me.RecordsetClone
         recClone.Close
End Sub

Am I missing something? Can anyone help me?

Thanks in advance,
Jason
 
The problem is your last statement.

You never open the recordset so you shouldn't close it.

I'm not sure what the point is of the last but one statement either.
 
I removed the "recClone.Close"
statement but there is no change. Any other ideas?

Thanks,
Jason
 
When I remove the subform from the form it works perfectly. Does that help?
 
To try to diagnose the problem rename the procedure and create a new Form current procedure with just this

Private Sub Form_Current()
Dim recClone As Recordset
Set recClone = Me.RecordsetClone
Set recClone = nothing
end sub

See if you get any errors.
 
Lupins,

I did what you said and now it seems to work okay. However, I still get the error when I have the form open then switch to design view. Once I switch from design view to runtime I get the error again. when I close the form all together and reopen it the error is not there. Do you know why this might be happening. I hope I've explained it well enough.

steps to get error:
1. open form
-no error
2. switch to design view
3. switch back to runtime
-error
4. close form
5. open form
-no error

Thanks again,
Jason
 
I'm stumped on this can someone PLEASE help?
 
Once again when I remove the subform everything works fine. What is going on? Sorry to sound pushy but this is becoming an urgent matter here.

Thanks,
Jason
 
have a look at the code I use for navigation, it is in

thread702-800384

You should be able to pick out what you require

Hope this helps
Hymn
 
I assume the code you have shown is in the main form, not the subform?
How is the subform linked to the main form?
Is the subform a single form or a continuous form ?(or something else?)

If the code works correctly when you don't go into design view then this would qualify as 'working' wouldn't it?
 
Yes the code is in the main form. The subform is linked to the main form by one field. Child field is RFQnum, Master field is RFQNumber. The subform is a continuous form. Yes it would Qualify as working but that is just with the sample code you supplied. When I add the rest of my code it errors out as soon as I come across a record with corrisponding records in the subform. However when I eliminate the subform, my code works perfectly. Hope this helps.

Thanks again,
Jason
 
hymn,

I used your code and just like before it works perfectly until I get to a record that has data in the subform then it errors out. Also when I eliminate the subform it works perfectly. I know it has somethign to do with this subform but I don't know what.

Thanks,
Jason
 
I have tried your original code (minus the last two lines) on a form/subform created from northwind orders and order details tables and it works fine.

So we have to start looking at your Access installation.
Do you have the service eleases for Office 97 installed?

The other area to consider is what code you have in the subform.
 
Thank you for all your help everyone. I have found the problem. It was some code in my subform that I was using for security purposes. I can't believe I didn't find it sooner. Mostly I just forgot it was there. Thanks for pointing me in the right direction lupins. I very much appreciate all of your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top