Results 1 to 3 of 3

Thread: Excel

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    23

    Excel

    Hi -

    I need to list an xls file's fields in a listbox 'List1'. The xls is selected from a filelistbox 'File2'.

    This is the following code I am using but it keeps on telling me that the filename 'TEMP.XLS' could not be found, although I have checked that the path and filename is correct.

    For n1 = 0 To (File2.ListCount - 1) 'Counts the number of xls files
    If File2.Selected(n1) = True Then 'Checks if a xls has been selected
    dbfsel = File2.List(n1) 'The selected xls
    End If
    Next

    Set DBase = opendatabase ("D:\Erwin_files\My_Data\User_Request\Erwin\DEL_Multiple_fields\Table\TEMP.XLS", False, False, "EXCEL 8.0;")

    THE FILE NOT FOUND MSG COMES UP WHEN THIS 'SET' STRING IS EXECUTED
    Set rs = DBase.OpenRecordset(dbfsel) 'dbfsel is the selected xls

    With rs
    For n2 = 0 To rs.Fields.Count - 1
    List1.AddItem rs.Fields(n2).Name
    Next n2
    End With

    rs.Close



    Thanx in advance

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Excel

    You have already opened a connection to the excel spreadsheet with this line

    vb Code:
    1. Set DBase = opendatabase ("D:\Erwin_files\My_Data\User_Request\Erwin\DEL_Multiple_fields\Table\TEMP.XLS", False, False, "EXCEL 8.0;")

    when you are opening a recordset to it you should be passing it the Sheet name or number like "Sheet1"

    Set rs = DBase.OpenRecordset("Sheet1")
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    23

    Re: Excel

    Quote Originally Posted by NeedSomeAnswers
    You have already opened a connection to the excel spreadsheet with this line

    vb Code:
    1. Set DBase = opendatabase ("D:\Erwin_files\My_Data\User_Request\Erwin\DEL_Multiple_fields\Table\TEMP.XLS", False, False, "EXCEL 8.0;")

    when you are opening a recordset to it you should be passing it the Sheet name or number like "Sheet1"

    Set rs = DBase.OpenRecordset("Sheet1")
    Hi -

    Thanx for the advise; much appreciated

    Regards
    Erwin

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