Junk filed headers

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi,

When I try to open a recordset for a tab delimited csv file, the field names
are not properly displayed. Its showing some junk field names. First row in
the csv file is header row which contains the field name

Public Function GetCSVRecordset(ByVal sLocation As String, ByVal sFileName
As String) As ADODB.Recordset
On Error GoTo ErrorHandler
Dim objFSO As New Scripting.FileSystemObject
Dim objCon As New ADODB.Connection
Dim objRS As New ADODB.Recordset
Dim sFileLoc As String

sFileLoc = sLocation

If Not objFSO.FileExists(sFileLoc & "\" & sFileName) Then
MsgBox sFileLoc & "\" & sFileName & " is missing. Please place the
file " & sFileName & " in " & sLocation
Set objFSO = Nothing
Exit Function
End If

objCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sFileLoc &
";" & _
"Extended Properties=""text;HDR=YES;FMT=Delimited"""

objRS.CursorLocation = adUseClient

objRS.Open "select * from [" & sFileName & "]", objCon, adOpenKeyset,
adLockOptimistic
objRS.ActiveConnection = Nothing
Set GetCSVRecordset = objRS
Set objCon = Nothing
Set objFSO = Nothing
Exit Function
ErrorHandler:
MsgBox "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
& vbCrLf & "Error Source: " & Err.Source
Set GetCSVRecordset = Nothing
Set objCon = Nothing
Set objFSO = Nothing
End Function

Please find below the immediate window
?objrs.Fields(0).Name
ÿþS
?objrs.Fields(1).Name
sites#csv.NoName

I am using schema.ini file also, for specifying the Delimiter.

Please tell me what could be the reasons and how to resolve this.

Regards,
M. Abdhul Saleem.
.



Relevant Pages

  • Re: Filling Html table
    ... > html table with the data from the file instead of hard-code them to the ... '* Reads a CSV file, formats a HTML table, and writes a HTM file. ... Dim arrCSV ... Set objFSO = CreateObject ...
    (microsoft.public.scripting.vbscript)
  • Re: CSV File not fully imported
    ... Do NOT append files where the file broke and quit importing mid-stream, just delete the partial import temp table contents and move to the next file. ... Create a new folder in the current folder where the source (big CSV file) is. ... Dim Cycle As Integer ... Dim myCount As Long ...
    (microsoft.public.access.externaldata)
  • Problem getting newly created user accounts enabled and password n
    ... Dim sIOLocation ... Dim oInputConnection ... ' Location of CSV file and to which log files will be written ... ' Indicates that the user account will use default mail store rules ...
    (microsoft.public.windows.server.scripting)
  • RE: CSV code works on some, but not all machines
    ... Dim thisSheet As Worksheet ... If Len(Dir(strPath & strCSVFileName))> 0 Then ... 'CSV file exists. ... Set newBook = Workbooks.Open ...
    (microsoft.public.excel.programming)
  • RE: Code Interpretation
    ... For the bottom of the code I'm assuming PRICES is a sheet called Test.xls, ... objWSExport.Visible = False hides the saved .csv file from view. ... Dim objWBExport As Workbook ... Set objWSExport = objWBPrice.Worksheets ...
    (microsoft.public.excel.programming)