Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-01-16
2
Medium Priority
?
289 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 2000 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

926 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