473,503 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Import text file to MS Access - Skip first 11 lines

4 New Member
Hi

I am trying to import a text file into a MS Access database. The first 11 lines of the text file are in a different format, so i would like to skip those lines and start at line 12. is there a quick and easy way to skip lines using VB in Access. Here is a sample of my text file:

[FILE]

SDS 2.2 AD Results 1.0
Filename
PlateID
Assay Type
Run DateTime
Operator

Sample Information
Marker Setting Information
Marker Name Quality Value Threshold

Well Sample Name Marker Name Allele X Rn Allele Y Rn
1 snp IRF6-SNP13 0.313 0.700
2 snp IRF6-SNP13 0.507 0.634
3 snp IRF6-SNP13 0.434 0.741
[/FILE]


Any help on skipping to line 12 would be greatly appreciated. Thanks in advance

TJ
May 14 '07 #1
3 20546
kepston
97 Recognized Expert New Member
You can skip the first 11 lines using the following code to generate a temporary file, then import from that file. I have tested the code with your sample (with the exception of the actual import - DoCmd.TransferText)

Expand|Select|Wrap|Line Numbers
  1.     Const ForReading = 1, ForWriting = 2, ForAppending = 3
  2.     Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
  3.     Dim ft, fs, t, s, temp, sample
  4.     Set fs = CreateObject("Scripting.FileSystemObject")
  5.     Set ft = CreateObject("Scripting.FilesystemObject")
  6.     fs.opentextfile "sample.txt" 'your text file
  7.     ft.createtextfile "temp.txt" 'create a temporary file
  8.     Set s = fs.getfile("sample.txt")
  9.     Set t = fs.getfile("temp.txt")
  10.     Set temp = t.OpenAsTextStream(ForWriting, TristateUseDefault)
  11.     Set sample = s.OpenAsTextStream(ForReading, TristateUseDefault)
  12.  
  13.     For x = 1 To 11  'read first 11 lines
  14.         sample.readline
  15.     Next x
  16.  
  17.     Do While Not sample.atendofstream    'read remainder of file until end
  18.         temp.writeline (sample.readline) 'write a line at a time
  19.     Loop
  20.  
  21.     temp.Close
  22.     sample.Close
  23.  
  24.     DoCmd.TransferText acImportFixed, _
  25.                         "Your import spec", _
  26.                         "your table name", _
  27.                         "temp.txt", _
  28.                         True
  29.  
  30.  
See my previous post for selecting a file using a dialog box
May 15 '07 #2
tjuiowa
4 New Member
Thank you so much...this was a big help!

You can skip the first 11 lines using the following code to generate a temporary file, then import from that file. I have tested the code with your sample (with the exception of the actual import - DoCmd.TransferText)

Expand|Select|Wrap|Line Numbers
  1.     Const ForReading = 1, ForWriting = 2, ForAppending = 3
  2.     Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
  3.     Dim ft, fs, t, s, temp, sample
  4.     Set fs = CreateObject("Scripting.FileSystemObject")
  5.     Set ft = CreateObject("Scripting.FilesystemObject")
  6.     fs.opentextfile "sample.txt" 'your text file
  7.     ft.createtextfile "temp.txt" 'create a temporary file
  8.     Set s = fs.getfile("sample.txt")
  9.     Set t = fs.getfile("temp.txt")
  10.     Set temp = t.OpenAsTextStream(ForWriting, TristateUseDefault)
  11.     Set sample = s.OpenAsTextStream(ForReading, TristateUseDefault)
  12.  
  13.     For x = 1 To 11  'read first 11 lines
  14.         sample.readline
  15.     Next x
  16.  
  17.     Do While Not sample.atendofstream    'read remainder of file until end
  18.         temp.writeline (sample.readline) 'write a line at a time
  19.     Loop
  20.  
  21.     temp.Close
  22.     sample.Close
  23.  
  24.     DoCmd.TransferText acImportFixed, _
  25.                         "Your import spec", _
  26.                         "your table name", _
  27.                         "temp.txt", _
  28.                         True
  29.  
  30.  
See my previous post for selecting a file using a dialog box
Aug 17 '07 #3
PappyBlueRibs
1 New Member
Wow, this is so useful! I've got about 15 data files that I'm using it with, no problem at all. Thank you!
Feb 20 '12 #4

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

Similar topics

2
3052
by: David Berry | last post by:
Hi All. I'm looking for any help or sample code that can show me how to make a file import wizard in ASP.NET (VB preferred) like the one that MS Access uses. I'm working on a web site where the...
1
9716
by: DCM Fan | last post by:
Access 2K, SP3 on Windows 2K, SP4 All, I have an import spec set up with quoted Identifiers and comma-separated values. The text file is produced by a 3rd-party program of which I have no...
1
6681
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my...
5
11542
by: Johnny Meredith | last post by:
I have seven huge fixed width text file that I need to import to Access. They contain headers, subtotals, etc. that are not needed. There is also some corrupt data that we know about and can...
4
9457
by: khutch | last post by:
Not that up on MS Access. I understand that the TransferText command can be used to import csv files into a database. Question: Does the text file have to mirror the alignment of the table columns...
1
3754
by: ghadley_00 | last post by:
Hi, I have a MS access database table for which I regularly need to import fixed width text data. At present I have to to cut and paste the text data from its source to a text file, save the...
1
2143
by: NathanB | last post by:
Hi there, I have a text file (flat file) which I would like to import on a regular basis into Access. The text file contains 2 record types, header (prefixed with RHD) and detail (prefixed with...
1
2667
by: Wandering | last post by:
I know you guys are heavy duty coders, while I do ad-hoc analysis, and rarely write code. And, I may be in the wrong groups because this is about an install issue, and I don't think it's a code...
14
11151
by: mfrsousa | last post by:
hi there, i have a huge large text file (350.000 lines) that i want to import to a MS Acccess Database, of course i don't want to use Access, but do it with C#. i already have tried the...
0
7199
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
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7274
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
7323
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...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4670
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
3162
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
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.