Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft Access > Opening Excel f...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 28 Topic 30361 of 31576
Post > Topic >>

Opening Excel from Access

by "Phil Stanton" <phil@[EMAIL PROTECTED] > May 25, 2008 at 02:40 PM

I have a form with a button which is supposed to open an Excel file (With 
lots of Macros /VBA) in it. The Excel file gets it's data from the Access 
program

Here is the code

Private Sub Storage_Click()

    On Error GoTo Err_Storage_Click

    Dim ExcelApp As Object
    Dim ExcelWasNotRunning As Boolean           ' Flag for final release
    Dim XLFilePath As String
    Dim XLName As String                        ' Excel file name from
Paths
    Dim MyDb As Database
    Dim Msg As String

    ' Find the normal path
                                          ' Folder and File
    If Nz(ExcelPath) = "" Then
        ExcelPath = "C:\Storage.XLS"
    End If

    XLName = Right(ExcelPath, Len(ExcelPath) - InStrRev(ExcelPath, "\")) 
' File Name

    If Dir(ExcelPath) <> XLName Then          ' Not found
        XLFilePath = FindFile("C:\Do***ents and Settings\Phil\My 
Do***ents\Access\MDB\WFYC\", XLName)
        Msg = "The name of the file you have selected is " & vbCrLf
        Msg = Msg & XLFilePath & vbCrLf
        Msg = Msg & "but the original file was " & vbCrLf
        Msg = Msg & ExcelPath & vbCrLf
        Msg = Msg & "Do you want to use the new name in future?"
        If MsgBox(Msg, vbQuestion + vbYesNo) = vbYes Then
            ExcelPath = XLFilePath
        End If
    End If

    Set ExcelApp = CreateObject("Excel.Application")

    If Err.Number <> 0 Then ExcelWasNotRunning = True
    Err.Clear    ' Clear Err object in case error occurred.

    ' Set the object variable to reference the file you want to see.

    Set ExcelApp = CreateObject("Excel.Application")
    ExcelApp.WorkBooks.Open ExcelPath, , True                   ' Read
Only
    ExcelApp.Visible = True

Exit_Storage_Click:
    Exit Sub

Err_Storage_Click:
    If Err = 2447 Then              ' Corrupted File name (with # sign)
        Resume Next
    Else
        MsgBox Err.Description
        Resume Exit_Storage_Click
    End If

End Sub

When I run it, I get an Error Box "ODBC Microsoft Access Driver Login 
Failed" and the message "The database has been placed in a state by user 
'Admin' on Machine 'PHIL-DESKTOP' that prevents it being opened or locked"

What am I doing wrong

Thank

Phil
 




 28 Posts in Topic:
Opening Excel from Access
"Phil Stanton"   2008-05-25 14:40:17 
Re: Opening Excel from Access
"Phil Stanton"   2008-05-25 16:59:21 
Re: Opening Excel from Access
"ByteMyzer" <  2008-05-25 11:43:18 
Re: Opening Excel from Access
"Phil Stanton"   2008-05-25 21:01:25 
Re: Opening Excel from Access
The Frog <Mr.Frog.to.y  2008-05-26 01:06:46 
Re: Opening Excel from Access
"Phil Stanton"   2008-05-26 09:36:55 
Re: Opening Excel from Access
Roger <lesperancer@[EM  2008-05-26 03:29:45 
Re: Opening Excel from Access
"Phil Stanton"   2008-05-26 22:33:00 
Re: Opening Excel from Access
The Frog <Mr.Frog.to.y  2008-05-27 00:35:04 
Re: Opening Excel from Access
"Phil Stanton"   2008-05-27 11:52:45 
Re: Opening Excel from Access
Roger <lesperancer@[EM  2008-05-27 03:52:52 
Re: Opening Excel from Access
"Phil Stanton"   2008-05-27 22:09:22 
Re: Opening Excel from Access
Roger <lesperancer@[EM  2008-05-28 03:21:18 
Re: Opening Excel from Access
"Phil Stanton"   2008-05-28 23:09:44 
Re: Opening Excel from Access
lyle fairfield <lyle.f  2008-05-28 15:33:59 
Re: Opening Excel from Access
"Phil Stanton"   2008-05-29 01:04:45 
Re: Opening Excel from Access
lyle fairfield <lylefa  2008-05-29 09:58:46 
Re: Opening Excel from Access
lyle fairfield <lylefa  2008-05-29 10:02:05 
Re: Opening Excel from Access
Roger <lesperancer@[EM  2008-05-28 18:43:20 
Re: Opening Excel from Access
Roger <lesperancer@[EM  2008-05-28 18:46:33 
Re: Opening Excel from Access
lyle fairfield <lyle.f  2008-05-28 19:45:43 
Re: Opening Excel from Access
"Keith Wilby" &  2008-05-29 08:28:42 
Re: Opening Excel from Access
"Phil Stanton"   2008-05-29 10:23:53 
Re: Opening Excel from Access
Roger <lesperancer@[EM  2008-05-29 01:54:32 
Re: Opening Excel from Access
Roger <lesperancer@[EM  2008-05-29 02:47:25 
Re: Opening Excel from Access
lyle fairfield <lyle.f  2008-05-29 05:25:38 
Re: Opening Excel from Access
"Phil Stanton"   2008-05-29 20:34:48 
Re: Opening Excel from Access
lyle fairfield <lyle.f  2008-05-29 05:31:12 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 22:55:28 CST 2008.