> hello,
>
[quoted text clipped - 10 lines]
>
> thank you a lot
It isn't clear if you are using free-standing VB, or VBA inside MSAccess.
Importing the data is similar with either case, but creating a new table
will differ. If using MSAccess VBA you have additional opportunities which
are likely better than using ADO - for example, you might simply "link" to
the external file and use a Make Table Query.
So if using VBA you should post to a MSAccess newsgroup.
If using a free-standing VB program Google for examples "MS Access ADO
import data file" and "ADOX" (for creating new tables). There are a ton of
possible methods. Find something that looks like it answers your problem,
then post back with code if you get stuck.
hth
-ralph
Dave - 13 Feb 2008 18:07 GMT
I would like import a text file with delimited semi-colon (;) but not with
comma (,)
When I run the VB source it's not ok. It's ok only with comma
Do you have a solution please
My Texte file
---------------
"F1";"F2";"F3"
"3"; "5"; "6"
"1";"2"; "3"
"1,5";"2,4";"3,6"
My Source
------------
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim PathtoTextFile As String
Dim PathtoMDB As String
Dim myarray() As Variant
Private Sub Form_Load()
PathtoTextFile = "C:\"
PathtoMDB = "C:\"
CmdOpen.Caption = "Open textfile and display field value"
CmdInsert.Caption = "Insert textfile values into MDB"
End Sub
Private Sub CmdInsert_Click()
Set Cat = New ADOX.Catalog
Set objTable = New ADOX.Table
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & PathtoMDB & "test.mdb"
'Open the Catalog
Set Cat.ActiveConnection = cn
'delete the table if it exists
On Error Resume Next
Cat.Tables.Delete "Table1"
'Create the table
objTable.Name = "Table1"
'Create and Append a new fields to the "table1" Columns Collection
objTable.Columns.Append "F1", adWChar
objTable.Columns.Append "F2", adWChar
objTable.Columns.Append "F3", adWChar
Cat.Tables.Append objTable
'Insert into table1 the contents of textfile.txt
cn.Execute "INSERT INTO Table1 SELECT * FROM " & _
"[Text;Database=" & PathtoTextFile & ";HDR=YES].[TextFile.txt]"
cn.Close
MsgBox "Finished Inserting into MDB"
End Sub
Ralph - 13 Feb 2008 18:45 GMT
> I would like import a text file with delimited semi-colon (;) but not with
> comma (,)
> When I run the VB source it's not ok. It's ok only with comma
> Do you have a solution please
Try a schema.ini file.
Open notebook. Type the following:
[TextFile.txt]
Format=Delimited(;)
Save it as "schema.ini" and place it in the same folder as the text file.
Take a look at the following article.
http://support.microsoft.com/kb/262537
Note: you have to change your connection string to include the Delimiter and
Hdr attributes.
Additional information:
http://www.aurigma.com/Support/DocViewer/5/AddingDatafromTextFile.htm.aspx
hth
-ralph