basil3legs
Programmer
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.
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] = ""
.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.