How to import a txt file in MS Access with VBA (2 Viewers)

jdraw

Super Moderator
Staff member
Local time
Today, 15:54
Joined
Jan 23, 2006
Messages
15,379
I just ran this code with spec SachExample
In Sample2 I modified dates to YMD format in the sample2.txt

Code:
Sub MyTableImport()
DoCmd.TransferText acImportDelim, "SachExample", "MyTesTTable", "C:\users\jp\documents\documents_Lenovo\Documents\Sample2.txt", True
End Sub

This the specification: 1643646514801.png



OutPut
MyTesTTable MyTesTTable

pernameperCityperstateperDoB
JohnMiamiFL
21-Apr-98​
BobChicagoIL
15-Nov-92​
FredTorontoON
30-Aug-01​
 

SachAccess

Active member
Local time
Tomorrow, 01:24
Joined
Nov 22, 2021
Messages
389
Can you post your sample.txt file --at least a few records?

My sample was delimited with |. I'd also like to see the design of Table1.
Update1
Just saw Doc's comment ---he's probably right about the trim with Dates.
Give me a few records and we'll get it working.

But it worked with my sample (my regional setting has DD-MMM-YY)
SachTable1 SachTable1

PersNamePersCityPersStatePersDoB
JohnMiamiFL
21-Apr-98​
BobChicagoIL
15-Nov-92​
FredTorontoON
30-Aug-01​
Can you post your sample.txt file --at least a few records?

My sample was delimited with |. I'd also like to see the design of Table1.
Update1
Just saw Doc's comment ---he's probably right about the trim with Dates.
Give me a few records and we'll get it working.

But it worked with my sample (my regional setting has DD-MMM-YY)
SachTable1 SachTable1

PersNamePersCityPersStatePersDoB
JohnMiamiFL
21-Apr-98​
BobChicagoIL
15-Nov-92​
FredTorontoON
30-Aug-01​
Sorry for late reply.
 

Attachments

  • Sample - Copy.txt
    316 bytes · Views: 137

SachAccess

Active member
Local time
Tomorrow, 01:24
Joined
Nov 22, 2021
Messages
389
Typically, "Data type conversion error" means you are trying to use something that is the wrong data type for the field in question. If you get to the line in question and J is 4, it points to a date field. I don't think Trim works correctly with date fields because dates are internally stored as numbers. Only the displayed date is text-oriented.
Thanks for the help. Have a nice day ahead. :)
 

jdraw

Super Moderator
Staff member
Local time
Today, 15:54
Joined
Jan 23, 2006
Messages
15,379
??Utilitatis|causa|amicitia|est|quaesita??
From Google translate ??Friendship is sought for the sake of advantage??

Repeated lines---is this your real data?
 

Users who are viewing this thread

Top Bottom