473,320 Members | 2,073 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Default Import Specification (for TransferText etc)

MIG
I am aware that when importing a file it's possible to save a
specification that says, for example, treat a particular field as
text, whenever importing a file of exactly the same format.

It's also possible to use the TransferText method with such a
specification as an argument.

However, it's a complete pain having to save a different specification
for every new file format.

It is infuriating that, without a specification, Access assumes that a
field which has an alphabetical character in the second record is
nevertheless an integer, and then fails to import half of the data.

Is there a way of telling Access to assume by default that EVERY field
is text, so save me having to save one specification after another,
all of which do the same thing?

Another question for when more users are involved: are the
specifications saved in the database or in the individual copies of
Access, requiring every user to save the same list of speficications?

Jul 23 '07 #1
2 4708
The specification is saved in the mdb where it was created. If you
create a new spec on an mdb and each user has a separate copy of the mdb
- you need to distribute that mdb so that everyone has an updated
version of it.

But instead of using a specificate, if you have to distribute the
application - it is much easier to use VBA code to write/read data
to/from textfiles. No specifications involved. Here is a sample:

---------------------------------------------
Sub writeDataToTextFile()
Dim DB As DAO.Database, RS As DAO.Recordset
Dim str1 As String, strPath As String, i As Integer
Set DB = CurrentDb
Set RS = DB.OpenRecordset("tbl1")
strPath = CurrentProject.Path
Debug.Print strPath
Close #1
Open strPath & "\testFile.txt" For Append As #1
Do While Not RS.EOF
str1 = ""
For i = 0 To RS.Fields.Count - 2
str1 = str1 & RS(i) & ","
Next
str1 = str1 & RS(i)
Print #1, str1 '--using print to output to a text file does not
add double quotes like the Write method
RS.MoveNext
Loop
Close #1
RS.MoveFirst
Open strPath & "\testFile2.txt" For Append As #1
Do While Not RS.EOF
str1 = ""
For i = 0 To RS.Fields.Count - 2
str1 = str1 & RS(i) & ","
Next
str1 = str1 & RS(i)
Write #1, str1 '--using Write surrounds the text in double quotes
" "
RS.MoveNext
Loop
RS.Close
Close #1

End Sub
-----------------------------------------------

The Access help files have more information on the "Open" statement,
"Append", "Close", "Line", "Input", "Split"
'--and here is sample code for reading from a text file
-------------------------------------------------
Sub ReadText()
Dim str1 As String, str2() As String
Dim i As Integer, j As Integer, k As Integer
Open "c:\somepath\testfile.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str1
str2 = Split(str1, vbTab)
For i = 0 To UBound(str2)
Debug.Print str2(i) & " ";
Next
Debug.Print
Loop
Close #1

End Sub
--------------------------------------------------

for reading text from textfiles, I use the Line method which reads each
line of text (delimited), and then I use the Split function to place
each datafield into an array -- str2(). You must have a table with the
same number of fields as the data you are reading in. You can loop
through the data in the text file using a Do While Loop, and then loop
through the Split array using a For loop as in the example above. Note:
using a semicolon at the end of the debug statement places the data in
the For loop on the same line. Without the ; each time you debug.print
something from str2(i) -- it would print on a new line in the debug
window.

HTH

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '07 #2
MIG
On Jul 23, 7:05 pm, Rich P <rpng...@aol.comwrote:
The specification is saved in the mdb where it was created. If you
create a new spec on an mdb and each user has a separate copy of the mdb
- you need to distribute that mdb so that everyone has an updated
version of it.

Ah; that's a Good Thing. Much easier than trying to change everyone's
local settings.

>
But instead of using a specificate, if you have to distribute the
application - it is much easier to use VBA code to write/read data
to/from textfiles. No specifications involved. Here is a sample:

Thanks. I will have a go at following it ...
>
---------------------------------------------
Sub writeDataToTextFile()
Dim DB As DAO.Database, RS As DAO.Recordset
Dim str1 As String, strPath As String, i As Integer
Set DB = CurrentDb
Set RS = DB.OpenRecordset("tbl1")
strPath = CurrentProject.Path
Debug.Print strPath
Close #1
Open strPath & "\testFile.txt" For Append As #1
Do While Not RS.EOF
str1 = ""
For i = 0 To RS.Fields.Count - 2
str1 = str1 & RS(i) & ","
Next
str1 = str1 & RS(i)
Print #1, str1 '--using print to output to a text file does not
add double quotes like the Write method
RS.MoveNext
Loop
Close #1
RS.MoveFirst
Open strPath & "\testFile2.txt" For Append As #1
Do While Not RS.EOF
str1 = ""
For i = 0 To RS.Fields.Count - 2
str1 = str1 & RS(i) & ","
Next
str1 = str1 & RS(i)
Write #1, str1 '--using Write surrounds the text in double quotes
" "
RS.MoveNext
Loop
RS.Close
Close #1

End Sub
-----------------------------------------------

The Access help files have more information on the "Open" statement,
"Append", "Close", "Line", "Input", "Split"

'--and here is sample code for reading from a text file
-------------------------------------------------
Sub ReadText()
Dim str1 As String, str2() As String
Dim i As Integer, j As Integer, k As Integer
Open "c:\somepath\testfile.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str1
str2 = Split(str1, vbTab)
For i = 0 To UBound(str2)
Debug.Print str2(i) & " ";
Next
Debug.Print
Loop
Close #1

End Sub
--------------------------------------------------

for reading text from textfiles, I use the Line method which reads each
line of text (delimited), and then I use the Split function to place
each datafield into an array -- str2(). You must have a table with the
same number of fields as the data you are reading in. You can loop
through the data in the text file using a Do While Loop, and then loop
through the Split array using a For loop as in the example above. Note:
using a semicolon at the end of the debug statement places the data in
the For loop on the same line. Without the ; each time you debug.print
something from str2(i) -- it would print on a new line in the debug
window.

HTH

Rich

*** Sent via Developersdexhttp://www.developersdex.com***

Jul 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
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...
2
by: ms | last post by:
In Access 2000, I am using... 'Import Raw text to stageBMIDLog table. DoCmd.TransferText acImportFixed, "BMIDLog Link Specification", "stageBMIDLog", file ....to import raw records into a...
1
by: Shaun Harwood | last post by:
Hello all Here is a puzzle I hope someone has a solution for. I am trying to import a delimited text file using a Visual Basic 'TransferText' command. So that the table is created properly I...
4
by: orange | last post by:
I've got a database in .txt file similar to this: BookName;Author;Year;ReviewedBy;Rating;Pages Nemesis;Isaac Asimov;1989;13,31,24;good;110 Sense & Sensibility;Jane Austen;1970;45,32;great;120...
3
by: Typehigh | last post by:
I am a pretty saavy user, but I am having a real problem with the DoCmd.TransferText operation. I manually used the File>Get External Data> Import routine to set up an import specification. It...
1
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...
5
by: bwlee | last post by:
Hi All, I'm attempting to automate the import of .txt files into Access. When I use the File > Get External Data > Import function and select my import specification, the data is imported...
4
by: WillMiller | last post by:
Hi, I'm currently attempting to write a small Access Database which carries out the following tasks : 1. Imports Submission files (of a text variety) to a table using TransferText on a daily...
3
by: Greg Strong | last post by:
Hello All, Why does Access (2003) create indexes on importing a CSV file to a table when using the TransferText Method in VB when the specification name does NOT have any indexes indicated? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.