Results 1 to 4 of 4

Thread: [RESOLVED] Permission denied

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Resolved [RESOLVED] Permission denied

    Hi All,
    I am using this method reading Excel .

    Code:
    Private Sub Command1_Click()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
     Sql = "Select * from [Call Summary$] Where F2 Is Not Null And F3 Is Not Null and F4 Is Not Null "
            ConnectionString = GetDriverString("D:\NewSampleFile.xls", "xls")
            Set cn = New ADODB.Connection
                With cn
                    .ConnectionString = ConnectionString
                    .Open
                    If .State = 1 Then
                        Set rs = New ADODB.Recordset
                        cn.CursorLocation = adUseClient
                        rs.Open Sql, cn, adOpenDynamic, adLockOptimistic
                        rs.Close
                    End If
                End With
                cn.Close
                Set rs = Nothing
                
              Set cn = nothing
        Dim fso As New FileSystemObject
        fso.MoveFile "D:\NewSampleFile.xls", "d:\test\"
    End Sub
    Public Function GetDriverString(ByVal sFileName As String, ByVal Extension As String) As String
        Dim strProvider As String
        Select Case Extension
        
            Case "xls"
                strProvider = "Provider=MSDASQL;DSN=Excel Files;Uid=;Pwd=;Dbq=" & sFileName & ";"
                GetDriverString = strProvider
                    
            Case Else
                'Do nothing
            End Select
    
    End Function
    And during the Moving File I get the Permission denied Error. Any ideas ?
    Last edited by danasegarane; Jul 21st, 2009 at 10:38 AM.
    Please mark you thread resolved using the Thread Tools as shown

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Permission denied

    The connection is probably not closed yet. Try adding a DoEvents call before the MoveFile call.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Permission denied

    Do you get the error if you unrem and fix the line (typo in your pose): Set cn = Nothing

    While file is opened in a connection I don't think there is any way you can move the file.

    Edited: A DoEvents may be the ticket as Joacim pointed out. But recommend setting cn = Nothing too.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Permission denied

    Never Mind it worked...

    The thing was that One Excel instance was locking the file in the background . After I killed that instance using Process Manager it worked....

    Thanks for your time


    LaVolpe
    Joacim Andersson
    Last edited by danasegarane; Jul 21st, 2009 at 10:42 AM.
    Please mark you thread resolved using the Thread Tools as shown

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width