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

ADO help with Access button for Excel wb?

Status
Not open for further replies.

BusMgr

IS-IT--Management
Aug 21, 2001
138
US
I am trying to create a button on an Access form that will save the current linked active Excel wb. The first time I want to save it the file name will be changed (using save as), after that I want to do a save or save as to save the updated wb to the same file.

My current code works some of the time (weird) and other times I get Err code 91-(Object variable not set) I've been told that I am not declaring the Excel wb object correctly and that ADO is the answer.

VBA code for button as follows:
Private Sub Command6_Click()
On Error GoTo Error_Command6_Click
Dim Wb As Workbook
Dim AWb As String
AWb = ActiveWorkbook.Name
Dim mypath As String
Dim filebody As String
MsgBox "The name of the Active Workbook is " & AWb
mypath = "D:\RBI Tools\"
filebody = "Pipetally2"
wellinfo = Forms![Form2]![WellName]
ActiveWorkbook.SaveAs Filename:=mypath & filebody & wellinfo & ".xls", FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
' Close Excel and clear the object varibles
ActiveWorkbook.Close
Application.Quit
Exit_Command6_Click:
Exit Sub
Error_Command6_Click:
MsgBox CStr(Err) & " " & Err.Description & "
Resume Exit_Command6_Click
End Sub

Thanks in advance.

BusMgr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top