Solved

Getting "object invalid or no longer set" error on form close

Posted on 2013-01-16
2
278 Views
Last Modified: 2013-01-16
I'm getting "object invalid or no longer set" error when I click a command button to close a form.  Here is the code.  Can someone spot the problem for me?

Private Sub cmdMainMenu_Click()
On Error GoTo Err_cmdMainMenu_Click
   
    If Me.chkbxFinGoodsInvApplied = True Then
   
    Dim intLoop As Integer
    Dim rs As dao.Recordset

    'Start of code to write records to tblFinGoods if part is NOT serialized and applied qty is >0
    If Me.chkbxSerialize = False Then

    Set rs = CurrentDb.OpenRecordset("tblFinGoods")

    'For intLoop = 1 To IIf(Me.chkbxSerialize = False And Me.txtAppliedInvQty > 0, 1, Me.txtAppliedInvQty)

        rs.AddNew

        rs!OpenOrdRecID = txtRecID
        rs!Cust = Me.txtCustomer_1
        rs!DateFin = #10/10/2020#
        rs!PartN = Me.txtPart_No
        rs!Qty = Me.txtAppliedInvQty
        rs!Comments = "This record is from applied inventory from the Open Order record entry."
       
        rs.Update
               
    End If

    rs.Close
    'End of code to write records to tblFinGoods if part is NOT serialized and applied qty is >0
   
   
   
    'Start of code to write records to tblFinGoods if part IS serialized and applied qty is >0
    If Me.chkbxSerialize = True Then
   
    Set rs = CurrentDb.OpenRecordset("tblFinGoods")

    For intLoop = 1 To IIf(Me.chkbxSerialize = True And Me.txtAppliedInvQty > 0, 1, Me.txtAppliedInvQty)

        rs.AddNew

        rs!OpenOrdRecID = txtRecID
        rs!Cust = txtCustomer_1
        rs!DateFin = #10/10/2020#
        rs!PartN = Me.txtPart_No
        rs!Qty = Me.txtAppliedInvQty
        rs!Comments = "This record is from applied inventory from the Open Order record entry."

        If Me.chkbxSerialize = True Then
            rs!Serial = "ToCome"
            rs!SerialUsed = True
        End If
       
        rs.Update
               
    Next

    End If

    rs.Close
    'End of code to write records to tblFinGoods if part IS serialized and applied qty is >0

    End If

    AllowClose = True

    DoCmd.Close
   
    DoCmd.OpenForm "frmMainMenu"

Exit_cmdMainMenu_Click:
    Exit Sub

Err_cmdMainMenu_Click:
    MsgBox Err.Description
    Resume Exit_cmdMainMenu_Click
   
End Sub
0
Comment
Question by:SteveL13
2 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38782989
Your rs.close looks like it is mis-placed.  Try this:

Private Sub cmdMainMenu_Click()
On Error GoTo Err_cmdMainMenu_Click
    
    If Me.chkbxFinGoodsInvApplied = True Then
    
    Dim intLoop As Integer
    Dim rs As dao.Recordset

    'Start of code to write records to tblFinGoods if part is NOT serialized and applied qty is >0
    If Me.chkbxSerialize = False Then

    Set rs = CurrentDb.OpenRecordset("tblFinGoods")

    'For intLoop = 1 To IIf(Me.chkbxSerialize = False And Me.txtAppliedInvQty > 0, 1, Me.txtAppliedInvQty)

        rs.AddNew

        rs!OpenOrdRecID = txtRecID
        rs!Cust = Me.txtCustomer_1
        rs!DateFin = #10/10/2020#
        rs!PartN = Me.txtPart_No
        rs!Qty = Me.txtAppliedInvQty
        rs!Comments = "This record is from applied inventory from the Open Order record entry."
        
        rs.Update
                
    End If

    rs.Close
    'End of code to write records to tblFinGoods if part is NOT serialized and applied qty is >0
    
    
    
    'Start of code to write records to tblFinGoods if part IS serialized and applied qty is >0
    If Me.chkbxSerialize = True Then
    
    Set rs = CurrentDb.OpenRecordset("tblFinGoods")

    For intLoop = 1 To IIf(Me.chkbxSerialize = True And Me.txtAppliedInvQty > 0, 1, Me.txtAppliedInvQty)

        rs.AddNew

        rs!OpenOrdRecID = txtRecID
        rs!Cust = txtCustomer_1
        rs!DateFin = #10/10/2020#
        rs!PartN = Me.txtPart_No
        rs!Qty = Me.txtAppliedInvQty
        rs!Comments = "This record is from applied inventory from the Open Order record entry."

        If Me.chkbxSerialize = True Then
            rs!Serial = "ToCome"
            rs!SerialUsed = True
        End If
        
        rs.Update
                
    Next
        rs.Close            '<----  ******* Move your rs.close here
    End If


    'End of code to write records to tblFinGoods if part IS serialized and applied qty is >0

    End If

    AllowClose = True

    DoCmd.Close
    
    DoCmd.OpenForm "frmMainMenu"

Exit_cmdMainMenu_Click:
    Exit Sub

Err_cmdMainMenu_Click:
    MsgBox Err.Description
    Resume Exit_cmdMainMenu_Click
    
End Sub

Open in new window

0
 

Author Comment

by:SteveL13
ID: 38783020
That took care of that issue but now another one comes up.  I'll post another question.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now