LARiot
Programmer
- Feb 7, 2007
- 232
Hi guys. Thanks for any help on this.
I'm opening an excel file using ADO the only thing is the header is not on the first line. There are about seven lines prior which are useless.
Thanks.
-Neema
I'm opening an excel file using ADO the only thing is the header is not on the first line. There are about seven lines prior which are useless.
Thanks.
Code:
Function ImportForecast()
Dim cn As ADODB.Connection
Dim rsTable As ADODB.Recordset
Dim varAllFiles As Variant
Dim strSQL As String
Dim strFile As String
Dim i As Integer
Set cn = CreateObject("ADODB.Connection")
Set rsTable = CreateObject("ADODB.Recordset")
varAllFiles = OpenFiles("Select Forecast file")
If blnCancel = True Then Exit Function
For i = 0 To UBound(varAllFiles)
strFile = varAllFiles(i)
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile & ";Extended Properties=""Excel 8.0;HDR=Yes;MaxScanRows=0;IMEX=0"";"
strSQL = "SELECT * FROM [Data Fcst Input$]"
rsTable.Open strSQL, cn
Do While Not rsTable.EOF
Debug.Print rsTable.Fields("Label") & " " & rsTable.Fields("Acct#")
rsTable.MoveNext
Loop
rsTable.Close
cn.Close
Next
DoCmd.SetWarnings True
MsgBox "Done."
End Function
-Neema