Question : Opening an Excel File from an Access Form button

I am using Access 97 and Excel 97

I need to open an excel file C:\MyFiles\Info.xls using a button on my Acess switchboard form.

If the file is already open I need to know through a msgbox that it is open and who on my network is using it.
Everybody has a logon username.

Can any of our experts please suggest codiing on the form button to achieve this.

Many thanks

Peter Whitts

Answer : Opening an Excel File from an Access Form button

Now, in Access you can check to see if teh text file exists (something like this):

Option Compare Database
Option Explicit
Dim myExcelOpen As Boolean

Private Sub (your event trigger)()
On Error GoTo Err_Trap

    Dim strFileName As String
'enter location of your text file (and it's name)
    strFileName = Dir(myIOFile)
        ' Check file if is missing.
        If strFileName <> "FileName.txt" Then
            ' The check file is not found so no one is in Excel
            myExcelOpen = True
       Else
            myExcelOpen = False
        End If

'Now check variable "myExcelOpen"
If myExcelOpen = True Then
'open the excel file
Else
msgbox "Someone is in the file.", vbokonly, "Cannot open"
End if


Exit_Error:
    Exit Sub

Err_Trap:
    Resume Next
End Sub

Random Solutions  
 
programming4us programming4us