Results 1 to 31 of 31

Thread: [RESOLVED]Using Ado To Access Excel Files

Threaded View

  1. #1

    Thread Starter
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Resolved [RESOLVED]Using Ado To Access Excel Files

    I am trying to read an Excel worksheet into an ADO recordset so that I can read the values from the Excel file. However, I cant seem to get this last part to work.

    I have tried everything I know - even searching the internet - but I cant seem to figure out why when I try to execute this line in the code

    VB Code:
    1. oRs.Open sRequest, sCnn, adOpenDynamic, adLockOptimistic
    I always seem to get the following error:

    The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure that the object exist and that its name and path name correctly.

    I know that Sheet1 exist in the Excels File Path.

    Any other ideas why this error is occurring? - Thanks In Advance

    VB Code:
    1. Private Sub Form_Load()
    2.    
    3.     Dim sPath As String
    4.     Dim oRs as ADODB.Recordset
    5.  
    6.     sPath = App.Path & "\Las Animas Text.xls"
    7.    
    8.     Set oRs = GetADOExcelRecordSet(sPath)
    9.    
    10. End Sub
    11.  
    12.  
    13. Private Function GetADOExcelRecordSet(ByVal Path As String, _
    14.                 Optional ByVal Headers As Boolean = True) As Recordset
    15.                
    16.     Dim sCnn As String
    17.     Dim sWorksheet As String
    18.     Dim sRequest As String
    19.    
    20.     sWorksheet = "Sheet1"
    21.    
    22.     Dim oCnn As ADODB.Connection
    23.     Set oCnn = New ADODB.Connection
    24.     Dim oRs As Recordset
    25.     Set oRs = New ADODB.Recordset
    26.    
    27.     sCnn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    28.             "Data Source=" & Path & ";" & _
    29.             "Extended Properties=""Excel 8.0;HDR=No" & _
    30.             IIf(Headers, "Yes", "No") & """"
    31.            
    32.     'Read a sheet:
    33.  
    34.     sRequest = "SELECT * FROM [" & sWorksheet & "$]"
    35.     oRs.Open sRequest, sCnn, adOpenDynamic, adLockOptimistic
    36.     Set GetADOExcelConnection = oRs
    37.    
    38. End Function
    Last edited by Jumpercables; Jul 27th, 2005 at 01:34 PM.

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