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

Trouble Linking to Excel.

Status
Not open for further replies.

basil3legs

Programmer
Jun 13, 2002
157
GB
I have a Form with a button linked to the following code:

Private Sub ExcelLink_Click()

Dim MyXL As Object
Dim fs As Object
Dim ShelVal

Dim xlApp As Object
Dim objSheet As Object

Set fs = Application.FileSearch
With fs
Set xlApp = CreateObject("excel.application")
xlApp.Visible = True
.LookIn = "I:\Apps\WORD_P\QUOTES\"
.SearchSubFolders = False
If Not ((IsNull(Me![FILENAME])) Or (Me![FILENAME] = "")) Then
.FILENAME = Me![FILENAME]
If .Execute() > 0 Then
xlApp.Workbooks.Open "I:\APPS\WORD_P\QUOTES\" + Me![FILENAME]
Else
.FILENAME = Str(Me![ENQNUM]) + ".xls"
If .Execute() > 0 Then
xlApp.Workbooks.Open "I:\APPS\WORD_P\QUOTES\" + CStr(Me![ENQNUM]) + ".XLS"
Else
.FILENAME = Str(Me![ENQNUM]) + ".wk4"
If .Execute() > 0 Then
xlApp.Workbooks.Open "I:\APPS\WORD_P\QUOTES\" + CStr(Me![ENQNUM]) + ".WK4"
Else
xlApp.Workbooks.Open "I:\APPS\WORD_P\QUOTES\PS5.XLS"
Set objSheet = xlApp.Worksheets("QUOTE")
objSheet.Activate
xlApp.ActiveSheet.Cells(3, 3).Value = Me![ENQNUM]
xlApp.ActiveSheet.Cells(4, 3).Value = Me![CUSTOMER]
xlApp.ActiveSheet.Cells(5, 3).Value = Me![DESCRIPTIO]
xlApp.ActiveSheet.Cells(6, 3).Value = Me![CUST_PARTN]
xlApp.ActiveSheet.Cells(7, 7).Value = Me![CUST_ORDNO]
xlApp.ActiveSheet.Cells(7, 3).Value = Me![PSTK]
xlApp.ActiveSheet.Cells(3, 13).Value = Me![DATE_RCVD]
xlApp.ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
xlApp.ActiveWorkbook.SaveAs "I:\APPS\WORD_P\QUOTES\" + CStr(Me![ENQNUM]) + ".XLS"
End If
End If
End If
End If
End With

End Sub


Basically, it looks at the reference number for the record (an autonumber) and opens the file of the same name if it exists (in either Lotus or Excel format). If it isn't found, it creates the file in Excel and copies the relevant data over. This form is used for a new entry and the button does not work when the database is stored on the network. I have another form for viewing existing records with the same button and code and that always works fine. Also this form works fine if run locally, but not if the database is run from the network on the same machine.

Can anyone see any obvious errors?

Thanks in advance.
 
When the button is clicked, Excel does open but closes again immediately.
 
Ignore this thread, this is now sorted! I removed all the search parts which shouldn't find anything anyway as it is a new record - and it works fine now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top