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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADODB Excel Skips the first Record ???

Status
Not open for further replies.

rookie7799

Programmer
Apr 25, 2002
9
RU
Hi,
I encountered this weird problem ...

For some reason when I run the code below when going through records it skips the first one and shows the second one and so on???

This is what I have in Excel Sheet1:
A
1 666
2 555
3 444
4 333

So basically it skips 666 ??

Code:

Dim cnnExcel As ADODB.Connection, cnnExcel2 As ADODB.Connection, rstExcel As ADODB.Recordset, rst As ADODB.Recordset
Dim holidays(25) As String

Private Sub Form_Load()

strMainFilePath = "C:\Energy Metering\14-01.xls"
'"stand alone\Energy Metering Stand Alone.xls"
Set cnnExcel2 = New ADODB.Connection
Set rst = New ADODB.Recordset

With cnnExcel2
If .State = adStateOpen Then .Close
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Extended Properties").Value = "Excel 8.0"
.Open (strMainFilePath)
End With

rst.Open "Select * from [Sheet1$]", cnnExcel2, adOpenStatic, adLockOptimistic

rst.MoveFirst
Do Until rst.EOF
'Debug.Print rst.Fields(0)
holidays(Abs(rst.AbsolutePosition)) = rst.Fields(0)
rst.MoveNext
Loop
End Sub


ANY IDEAS ???
Thanks
 
Hi,

A quick look at this reveals that the values in row 1 of the spreadsheet are being used as the column names in the recordset. So if you wish to access the first row you can do so as a special case in your program by making reference to

Code:
holidays(0) = rst.fields(0).name

Hope this helps ...
 
The code that you wrote gave me "F1" everytime it goes through the loop...
Is there something I should do with it?
THanks
 
Try adding this:

.Properties("Extended Properties").Value = "Excel 8.0;HDR=NO"

If you want to pull the values for the first cell you must specify that you have no headers.

Swi
 
Thanks A LOT MAN!!! how in the world did i missed that...
thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top