Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Excel file into listbox

Status
Not open for further replies.

ReadyToRetire

Programmer
Feb 20, 2003
3
0
0
US
I am trying to read some dates which are located in column A from an excel file into a listbox. Everything works fine except it does not pick up the first row. The date ranges are from August 1,2003 through August 12, 2003. When I debug through the code, the first record is always 08/02/2003 (August 2,2003). I've tried using A1:A12 and A:A in the select statement to no avail. This is currently a test and the dates are going to be changed by the user on a yearly basis.

the following is the code :

**************************
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim sconn As String
Dim sfile As String

sfile = "C:\temp\test2.xls"
sconn = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" & sfile
rs.Open "SELECT * FROM [sheet1$]", sconn, 2, 2

Ii = 0

While Not rs.EOF
If Not rs.EOF Then
List1.List(Ii) = rs.Fields.Item(0).Value
rs.MoveNext
Ii = Ii + 1
End If
Wend

rs.Close

Set rs = Nothing

***************************************



Any help would be appreciated..... Thanks in advance
 
Hi,
It takes the first row as if it was the name of the field. Move everything down one row and give a title, if you like, it will work.

Jean-Paul
jp@solutionsvba.com


Jean-Paul
Montreal
mtljp2@sympatico.ca
 
Jean-Paul,

Thanks for replying. I have tried moving all the records down 1 row , 2 rows ...all the way to 10 rows and it still reads the second date field instead of the first. I have done a little research, and added a HDR=NO, but still have the same problem. I've read somewhere that the driver might have some problems. Have you heard of this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top