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
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) - Const ForReading = 1, ForWriting = 2, ForAppending = 3
-
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
-
Dim ft, fs, t, s, temp, sample
-
Set fs = CreateObject("Scripting.FileSystemObject")
-
Set ft = CreateObject("Scripting.FilesystemObject")
-
fs.opentextfile "sample.txt" 'your text file
-
ft.createtextfile "temp.txt" 'create a temporary file
-
Set s = fs.getfile("sample.txt")
-
Set t = fs.getfile("temp.txt")
-
Set temp = t.OpenAsTextStream(ForWriting, TristateUseDefault)
-
Set sample = s.OpenAsTextStream(ForReading, TristateUseDefault)
-
-
For x = 1 To 11 'read first 11 lines
-
sample.readline
-
Next x
-
-
Do While Not sample.atendofstream 'read remainder of file until end
-
temp.writeline (sample.readline) 'write a line at a time
-
Loop
-
-
temp.Close
-
sample.Close
-
-
DoCmd.TransferText acImportFixed, _
-
"Your import spec", _
-
"your table name", _
-
"temp.txt", _
-
True
-
-
See my previous post for selecting a file using a dialog box
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) - Const ForReading = 1, ForWriting = 2, ForAppending = 3
-
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
-
Dim ft, fs, t, s, temp, sample
-
Set fs = CreateObject("Scripting.FileSystemObject")
-
Set ft = CreateObject("Scripting.FilesystemObject")
-
fs.opentextfile "sample.txt" 'your text file
-
ft.createtextfile "temp.txt" 'create a temporary file
-
Set s = fs.getfile("sample.txt")
-
Set t = fs.getfile("temp.txt")
-
Set temp = t.OpenAsTextStream(ForWriting, TristateUseDefault)
-
Set sample = s.OpenAsTextStream(ForReading, TristateUseDefault)
-
-
For x = 1 To 11 'read first 11 lines
-
sample.readline
-
Next x
-
-
Do While Not sample.atendofstream 'read remainder of file until end
-
temp.writeline (sample.readline) 'write a line at a time
-
Loop
-
-
temp.Close
-
sample.Close
-
-
DoCmd.TransferText acImportFixed, _
-
"Your import spec", _
-
"your table name", _
-
"temp.txt", _
-
True
-
-
See my previous post for selecting a file using a dialog box
Wow, this is so useful! I've got about 15 data files that I'm using it with, no problem at all. Thank you!
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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 ...
| |