Hello. I have an issue that I am trying to sort through. I'm working with several (100's) or different csv files. I came upon a fairly large issue. I have a csv file format with three field names which are the exact same thing. My thought is that I would open the csv file using a DAO connection and write directly to the csv file. I'm not entirely sure if this is possible. I can read, see code...
Option Compare Database
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim rcd As New ADODB.Record
Dim PathtoTextFile As String
Dim PathtoMDB As String
Dim myarray() As Variant
Private Sub Form1()
PathtoTextFile = "C:\Users\Zach\Desktop\Zach.csv"
PathtoMDB = "C:\PathtoMDB\"
'CmdOpen.Caption = "Open textfile and display field value"
'CmdInsert.Caption = "Insert textfile values into MDB"
End Sub
Private Sub Command0_Click()
Dim n As Integer
Dim m As Integer
Dim rcd As ADODB.Record
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Users\Zach\Desktop;" & _
"Extended Properties=""text;HDR=Yes;FMT=Delimited;"";"
rst.Open "Select * From Zach.csv", cnn, , , adModeReadWrite 'adCmdText
'Debug.Print rst(1)
'For n = 1 To 6
'Debug.Print rst
'Next n
For n = 0 To 2
For m = 0 To 1
MsgBox rst.Fields(m).Name
Next m
m = 0
For m = 0 To 1
MsgBox rst.Fields.Item(m)
Next m
rst.MoveNext
Next n
If rst.Fields(0).Name <> rst.Fields(1).Name Then
rst.Fields(1).Name = "My Change"
Else
End If
rst.Close
cnn.Close
End Sub
I cannot write, however. See code segment...
If rst.Fields(0).Name <> rst.Fields(1).Name Then
rst.Fields(1).Name = "My Change"
Else
End If
I get the error "Can't assign to a read only property." I'm really wanting to do something like
For n = 1 To fieldcount
On Error Next, etc
If field
.name = field(n+1).name Then
field(n+1).name = field(n+1).name & "1"
Else
End If
Option Compare Database
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim rcd As New ADODB.Record
Dim PathtoTextFile As String
Dim PathtoMDB As String
Dim myarray() As Variant
Private Sub Form1()
PathtoTextFile = "C:\Users\Zach\Desktop\Zach.csv"
PathtoMDB = "C:\PathtoMDB\"
'CmdOpen.Caption = "Open textfile and display field value"
'CmdInsert.Caption = "Insert textfile values into MDB"
End Sub
Private Sub Command0_Click()
Dim n As Integer
Dim m As Integer
Dim rcd As ADODB.Record
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Users\Zach\Desktop;" & _
"Extended Properties=""text;HDR=Yes;FMT=Delimited;"";"
rst.Open "Select * From Zach.csv", cnn, , , adModeReadWrite 'adCmdText
'Debug.Print rst(1)
'For n = 1 To 6
'Debug.Print rst

'Next n
For n = 0 To 2
For m = 0 To 1
MsgBox rst.Fields(m).Name
Next m
m = 0
For m = 0 To 1
MsgBox rst.Fields.Item(m)
Next m
rst.MoveNext
Next n
If rst.Fields(0).Name <> rst.Fields(1).Name Then
rst.Fields(1).Name = "My Change"
Else
End If
rst.Close
cnn.Close
End Sub
I cannot write, however. See code segment...
If rst.Fields(0).Name <> rst.Fields(1).Name Then
rst.Fields(1).Name = "My Change"
Else
End If
I get the error "Can't assign to a read only property." I'm really wanting to do something like
For n = 1 To fieldcount
On Error Next, etc
If field

field(n+1).name = field(n+1).name & "1"
Else
End If