473,492 Members | 4,301 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Import Pipe Delimited Text File into Access table

6 New Member
Hello All,

I am a new to VBA and Access. I would like to build code to be able to import a text file to a access database table. The text file is piped delimited. I have attached a sample of it (MyText.txt). I have the following code in place, but it wont import properly. Its gives me type conversion errors as well as retains "|" in some fields after import. I have a specefication in place to do the same.

I should be able to browse for the Text file and be able to import it

Expand|Select|Wrap|Line Numbers
  1. Dim OpenFile As OPENFILENAME
  2.          Dim lReturn As Long
  3.          Dim sFilter As String
  4.          Dim chosenFile As String
  5.          Dim chosenFileName As String
  6.          Dim filelocString As String
  7.          Dim structurename As String
  8.          Dim tablename As String
  9.          filelocString = "T:\Test Scores"
  10.          structurename = "GRE"
  11.          tablename = "GRE"
  12.  
  13.          OpenFile.lStructSize = Len(OpenFile)
  14.          sFilter = "Text Files (*.txt)" & Chr(0) & "*.txt" & Chr(0)
  15.          OpenFile.lpstrFilter = sFilter
  16.          OpenFile.nFilterIndex = 1
  17.          OpenFile.lpstrFile = String(257, 0)
  18.          OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
  19.          OpenFile.lpstrFileTitle = OpenFile.lpstrFile
  20.          OpenFile.nMaxFileTitle = OpenFile.nMaxFile
  21.          OpenFile.lpstrInitialDir = filelocString
  22.          OpenFile.lpstrTitle = "Use the Comdlg API not the OCX"
  23.          OpenFile.flags = 0
  24.          lReturn = GetOpenFileName(OpenFile)
  25.          If lReturn = 0 Then
  26.             MsgBox "Action Cancelled"
  27.          Else
  28.  
  29.  
  30.             chosenFileName = OpenFile.lpstrFileTitle
  31.             chosenFile = OpenFile.lpstrFile
  32.                     DoCmd.TransferText acImportFixed, structurename, tablename, chosenFile
  33.                    End If
  34.        End Sub











Thanks for the help

BR,
vvasudev
Attached Files
File Type: txt MyText.txt (74 Bytes, 565 views)
Feb 22 '12 #1
1 9054
ADezii
8,834 Recognized Expert Expert
I had no problems whatsoever:
  1. The Transfer Type should be acImportDelim instead of acImportFixed. This is not a Fixed Width File.
  2. In the Specification, set all Field Data Types to Text, then convert if necessary, in Access, after the Data has been Imported into the specified Table.
Feb 22 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
7021
by: Padmaja | last post by:
Hello I want to convert a huge delimited text file (of appr 85MB) directly into XML. I dont want to loop through the text file and write as xml, as it is very large file and taking much time. ...
0
1252
by: TJS | last post by:
I need to import a delimited text file to an msde table, I found discussion item below. anything available for msde which is comparable to this Jet example? =================================...
0
1807
by: TJS | last post by:
attempting to read a delimited text file into a dataset using oledb text file connection getting this error message when trying to open connection...
0
1662
by: Masa Ito | last post by:
I have pipe delimited (and comma/tab) files that I read with JET using a schema file. Occasionally a field has multiple quotes (") inside a single field - which chokes the line (the rest of the...
1
5948
by: Stella | last post by:
Help!!! Am extremely new to VBA. Want to set up code behind a button that will prompt the user for a table name(source of data) and file name(end result of export) and then export the data into a...
1
6111
by: Pradeep | last post by:
Hi, I have the following task to be done in VC++ 6.0. I have a tab delimited text file that needs to be imported into a MS Access table. The table is created and the table structure is defined...
3
9049
by: shil | last post by:
Hi, I'm trying to find a right way the data from a TAB delimited UTF-8 text file into SQL database. My text file has Unicode characters like ö, é. I'm trying to code this in vb.net. Can any one...
3
2054
by: Seanw | last post by:
it is very large file, has 678000 rows. but the txt file get is like that "name","address","zip","state" ="11",="aaa",="00001",="NY" ="22",="bbb",="00002",="CT" ="33",="ccc",="00003",="NJ"...
1
8505
by: bhapate1 | last post by:
Hi all, I Have a Table with 10 Columns, Among those i have Data in just 3 Columns. Rest of columns wil be blank. I want to Export that Table as a Pipe Delimited Text File. I am using...
0
2213
by: rhonda6373 | last post by:
Is it possible to change the format of an Excel file to a pipe delimited text file? How can I do that? Thanks in advance!
0
7118
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7192
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.