run-time error 2467

C

Cyberwolf

I have a form that has a check box in the form footer called chkTBArchive. I
have a button on the same form footer that runs code that uses this check box
to run or not run specific queries based on its value. When I clikc the
button the code runs up to this point and errors out with a run-time error
2467 "The expression you entered refers to an object that is closed or
doesn't exist.

The strange thing is that I pulled this code from another form that contains
the same coding but the check box is part of the main form and is not on the
form footer.

Any help would be greatly appreciated. see code below

Private Sub butTBOps_Click()
'On Error GoTo Err_butTBOps_Click

Dim stDocName As String
Dim stDocName1 As String
Dim stDocName2 As String
Dim stDocName3 As String
Dim stDocName4 As String
Dim stDocName5 As String
Dim stDocName6 As String
Dim stDocName7 As String
Dim intResponse As Integer

Dim xlApp As New Excel.Application
Dim xlWkb As Excel.Workbook

DoCmd.Close acForm, "frm:Current TB", acSaveNo

DoCmd.RunMacro "mac:DelWalTB"

Set xlApp = New Excel.Application
Set xlWkb = xlApp.Workbooks.Open("G:\Accounting\AR\AR
Database\Macros.xls", 0)
xlApp.Visible = True
xlWkb.Windows(1).Visible = True

xlWkb.Application.Run ("Import_TB")

xlWkb.Close savechanges:=False
Set xlWkb = Nothing
xlApp.Quit
Set xlApp = Nothing


' This Deletes the info in the Old TB Table
stDocName2 = "qry:Del Old TB"
DoCmd.OpenQuery stDocName2, acViewNormal, acEdit
' This Copies the info From the Current TB to the Old TB
stDocName3 = "qry:Current TB to Old TB"
DoCmd.OpenQuery stDocName3, acNormal, acEdit
' This deletes the info in the Current TB
stDocName4 = "qry:Del Current TB"
DoCmd.OpenQuery stDocName4, acViewNormal, acEdit
' This Transfers the Delimited text file to the Current TB
DoCmd.TransferText acImportDelim, "kal-wal tb Import Specification",
"Current TB", "\\Pasvr\Group\Accounting\AR\AR Database\kal-wal TB.txt", True
' Copies the Old TB Status Info to the Current TB
stDocName5 = "qry:Update Current TB"
DoCmd.OpenQuery stDocName5, acViewNormal, acEdit

' This will copy the Old TB to the Archive TB if the Check box is checked
If chkTBArchive = True Then
stDocName = "qry:TB Archive"
DoCmd.OpenQuery stDocName, acNormal, acEdit
' This will add the week nunmber to the Archive TB
stDocName1 = "qry:TB Archive Week Update"
DoCmd.OpenQuery stDocName1, acViewNormal, acEdit


End If

'Message to state the Trial balance is loaded

MsgBox "The Current Trial Balance has been loaded.", vbOKOnly, "File
Operation Complete"

'Reopens the Current Trial Balance form

DoCmd.OpenForm "frm:Current TB", acNormal, , , acFormEdit, acWindowNormal

Exit_butTBOps_Click:
Exit Sub

Err_butTBOps_Click:
MsgBox Err.Description
Resume Exit_butTBOps_Click

End Sub
 
R

Ralph

Looks like you are closing your form with the check box before you run the
queries..
 
C

Cyberwolf

That did it. Sometimes it is the simplest things that get you. I should
have noticed this right off the top.

Thanks!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top