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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing Excel SS in Access w/command button

Status
Not open for further replies.

BusMgr

IS-IT--Management
Aug 21, 2001
138
US
I have an Excel ss that I open with a command button on a form in Access. I want to have another button on the form to close the ss after making changes to ss and save it with a different filename.

My code for the close button is as follows:

Private Sub CmdCloseSave_Click()
On Error GoTo Err_CmdCloseSave_Click

Dim oApp As Excel.Application
Dim objActiveWkb As Excel.Workbook
Dim fName As String
Dim wInfo As String

wInfo = Forms![frmDay]![WellID]
fName = DBPath & "PipeTally2-" & wInfo & ".xls"

Set oApp = GetObject(, "Excel.Application")
Set objActiveWkb = oApp.ActiveWorkbook
objActiveWkb.Close SaveChanges:=True, Filename:=fName

oApp.Quit
'Clear the object variable.
If fIsAppRunning("Excel") Then
If fCloseApp("XLMAIN") Then
End If
End If

It tells me that object variable or With block variable not set. This is happening at the objActiveWkb.close line of code.

I had it working with a similar db, but it will not work here. I know that if I only set the worksheet object, the binding does not occur until the code is run and I'll get an error message as above, but I don't see my problem.

Thanks in advance.
 
Maybe it should read:

Set objActiveWkb = New oApp.ActiveWorkbook

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top