473,473 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Importing Text File

I have a problem of importing a text file into Access. The text file
will be imported using a delimiter, say ( , ) for example. This should
be imported into the database. An example is:

John, is, a, boy
Ada, is, a, girl

I have tried using the DoCmd.TransferText but I am not getting results.

Nov 13 '05 #1
10 2933
hendafe wrote:
I have a problem of importing a text file into Access. The text file
will be imported using a delimiter, say ( , ) for example. This should
be imported into the database. An example is:

John, is, a, boy
Ada, is, a, girl

I have tried using the DoCmd.TransferText but I am not getting results.

If you use the Access File - Get External Data - Import command, you can
specify what delimiter, if any is to be used. Look closely when you do
this.

Bob
Nov 13 '05 #2
"hendafe" <he*****@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have a problem of importing a text file into Access. The text file
will be imported using a delimiter, say ( , ) for example.
Just to be pedantic, ( , ) is a "separator" not a delimiter.
A delimiter, if used, is usually double-quotes surrounding text.
Delimiters are needed around text fields so that commas can be included in
the text. eg
.... , "24 John Street, Bay Village", ...
This should be imported into the database.


What did that mean? Do you want the commas to be imported into the database
too?
If so, TransferText may not be the way to go.
Nov 13 '05 #3
I have tried using the Get External Data - Import command in the File
menu, and it is working perfectly well.
The problem, these text files are frequently added into a particular
folder, more than one.
I want to be able to loop through this folder and import the whole of
them into a table.
This should be done through a form, by clicking a command button.
Any help with that

Nov 13 '05 #4
Ian Hinson wrote:
"hendafe" <he*****@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have a problem of importing a text file into Access. The text file
will be imported using a delimiter, say ( , ) for example.

Just to be pedantic, ( , ) is a "separator" not a delimiter.
A delimiter, if used, is usually double-quotes surrounding text.
Delimiters are needed around text fields so that commas can be included in
the text. eg
... , "24 John Street, Bay Village", ...

This should be imported into the database.

What did that mean? Do you want the commas to be imported into the database
too?
If so, TransferText may not be the way to go.

Pedantic or not, the Access Import Text Wizard states:
"Delimited - Characters such as comma or tab separate each field".

Consider this definition I found through google,
de·lim·it·er (d-lm-tr)
n. Computer Science
A character or sequence of characters marking the beginning or end of a
unit of data.

Bob
Nov 13 '05 #5
Thanks.
The commas are not going to be imported into the database.
I am supposed to use a command button in a form to import
these files. The command button is supposed to collect these
different text files in the folder and transfer these text into a table
in the Database.
Any idea.

Nov 13 '05 #6
I have tried using the Get External Data - Import command in the File
menu, and it is working perfectly well.
The problem, these text files are frequently added into a particular
folder, more than one.
I want to be able to loop through this folder and import the whole of
them into a table.
This should be done through a form, by clicking a command button.
Any help with that

Nov 13 '05 #7
I have tried using the Get External Data - Import command in the File
menu, and it is working perfectly well.
The problem, these text files are frequently added into a particular
folder, more than one.
I want to be able to loop through this folder and import the whole of
them into a table.
This should be done through a form, by clicking a command button.
Any help with that

Nov 13 '05 #8

hendafe wrote:
Thanks.
The commas are not going to be imported into the database.
I am supposed to use a command button in a form to import
these files. The command button is supposed to collect these
different text files in the folder and transfer these text into a table
in the Database.
Any ideas.

Yes, when you imported via MS-Access's build import function, Access
save a spec. Run the process again and click on advance which should
be through the left on any of the forms. Your DoCmd.transfer will need
to use than spec as well.

As for as running a routine to process multiple files via one button,
you'll need use VBA.
Here is a sample project I did for a client:
Function IndexPC()
Set fs = Application.FileSearch
LoadCount = 0
PathStr(0) = DLookup("[Input Dir]", "ImportSettings", "[ID]
=0")
PathStr(1) = DLookup("[Archive Dir]", "ImportSettings", "[ID]
=0")
PathStr(3) = DLookup("[Archive File]", "ImportSettings", "[ID]
=0")
PathStr(4) = DLookup("[Purge File]", "ImportSettings", "[ID]
=0")
CurrentDb.Execute "Empty Files_New tbl"
With fs
For Counter = 1 To 1
.LookIn = PathStr(0)
.SearchSubFolders = False

.FileName = "*.PYX" 'Could be anything
If .Execute <> 0 Then
DoCmd.Echo True, "There were " & .FoundFiles.Count & _
" file(s) found."

DoCmd.OpenForm ("LoadFiles")
DoCmd.RepaintObject acForm, "LoadFiles"
For i = 1 To .FoundFiles.Count
'If Forms![LoadFiles]![File Name] Is Not Null Then
DoCmd.GoToRecord acForm, "LoadFiles", acNewRec
Forms![LoadFiles]![File Path Name] = .FoundFiles(i)
Forms![LoadFiles]![File Name] = Dir(.FoundFiles(i))
Forms![LoadFiles]![File Size] =
FileLen(Forms![LoadFiles]![File Path Name])
Forms![LoadFiles]![File Date/Time] =
FileDateTime(Forms![LoadFiles]![File Path Name])
'
NeedOLE = "No"
Age = DateDiff("d", Forms![LoadFiles]![File Date/Time],
Date)
If DCount("[File Path Name]", "Files_Loaded", "[File Path
Name]='" & Forms![LoadFiles]![File Path Name] & "'") < 1 Then NeedOLE =
"YES" 'prevent reloading if already in main table
If Age > 30000 Then Call DeleteFile
If NeedOLE = "YES" Then Call LoadOLE
Next i
Else
' MsgBox "There were no files found."
End If
Next Counter
End With
DoCmd.SetWarnings False
DoCmd.OpenQuery "Append New Files"
CurrentDb.Execute "Empty Files_New tbl"
DoCmd.Close acForm, "LoadFiles", acSaveNo
If PathStr(3) = "-1" Then Call CopyAllFiles(PathStr(0),
PathStr(1), "*.*")

MsgBox "Loaded " & LoadCount & " Files."

End Function

Nov 13 '05 #9
Here is another sample:

Function IndexPC()
Set FS = Application.FileSearch
DoCmd.SetWarnings False
CurrentDb.Execute "Empty New files tbl"
DoCmd.Close acForm, "LoadFiles"

With FS
For Counter = 1 To 1
DaysAge = DLookup("[Delete Days]", "FilePath", "[ID] = " &
Counter)
.LookIn = DLookup("[FilePath]", "FilePath", "[ID] = " & Counter)
'.LookIn = "%temp%"

.SearchSubFolders = True
.FileName = "*.*"
.Execute msoSortBySize, msoSortOrderDescending
i = .FoundFiles.Count
Beep
If i > 0 Then
DoCmd.Echo True, "There were " & .FoundFiles.Count & " file(s)
found."

DoCmd.OpenForm "LoadFiles", acDesign
DoCmd.OpenForm "LoadFiles", acNormal

For i = 1 To .FoundFiles.Count
'If Forms![LoadFiles]![File Name] Is Not Null Then
DoCmd.Echo True, .FoundFiles.Count - i
DoCmd.GoToRecord acForm, "LoadFiles", acNewRec
Forms![LoadFiles]![File Path Name] = .FoundFiles(i)
Forms![LoadFiles]![File Name] = Dir(.FoundFiles(i))

Forms![LoadFiles]![File Size] =
FileLen(Forms![LoadFiles]![File Path Name])
Forms![LoadFiles]![File Date/Time] =
FileDateTime(Forms![LoadFiles]![File Path Name])
' Forms![LoadFiles]![Owner] = DLookup("[Owner]", "File
Locations", "[Order]=" & Counter)
Forms![LoadFiles]![Folder] = Left$(.FoundFiles(i),
Len(.FoundFiles(i)) - Len(Dir(.FoundFiles(i))))
Forms![LoadFiles]![Projection] =
FileDateTime(Forms![LoadFiles]![File Path Name]) + DaysAge
Age = DateDiff("d", Forms![LoadFiles]![File Date/Time],
Date)

If Age > DaysAge Then Call DeleteFile
'Forms![LoadFiles]![Folder] =
Forms![LoadFiles]![Folder] & " -->" &
FileLen(Forms![LoadFiles]![Folder])
' RmDir Forms![LoadFiles]![Folder]
Next i
Else
MsgBox "There were no files found."
End If
Next Counter
End With
DoCmd.OpenQuery "Append New Files"
End Function

Sub DeleteFile()
Forms![LoadFiles]![Delete] = "Yes"
Kill Forms![LoadFiles]![File Path Name]
' DoCmd.RunCommand acCmdDeleteRecord
End Sub

Nov 13 '05 #10
-
Check out this download ...
http://amazecreations.com/datafast/d...owseImport.zip

Not sure where the Browse code came from. Have been using it for years
and probably got it from the MVP site, Dev Ashish.

--
"hendafe" <he*****@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I have a problem of importing a text file into Access. The text file
will be imported using a delimiter, say ( , ) for example. This should
be imported into the database. An example is:

John, is, a, boy
Ada, is, a, girl

I have tried using the DoCmd.TransferText but I am not getting results.

Nov 14 '05 #11

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

Similar topics

11
by: Grim Reaper | last post by:
I am importing a .csv file into Access that has 37 fields. My problem is that sometimes the last field only has data at the end of the column (it looks like when you import a file into Access, for...
1
by: sparks | last post by:
I have never done this and wanted to ask people who have what is the best way. One person said import it to excel, then import it into access table. but since this will be done a lot, I am...
6
by: Sam Lazarus | last post by:
I need to import data from a website, but the text is arranged badly: Name:John Doe Title:Grunt ID:314159 Name:Jane Doe Title:Queen-Bee ID:271828 etc...
2
by: kuhni | last post by:
Hi everybody, I am totally desperate because I cannot solve a really simple problem: I have a specific text-file which I want to import into an existing database. The problem is that the columns...
11
by: panic attack | last post by:
Hello everbody, Our system is using Sql Server 2000 on Windows XP / Windows 2000 We have a text file needs to be imported into Sql Server 2000 as a table. But we are facing a problem which is,...
5
by: hharriel | last post by:
Hi, I am hoping someone can help me with an issue I am having with excel and ms access. I have collected data (which are in individual excel files) from 49 different school districts. All...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
2
by: Debbiedo | last post by:
I have a text file that I am importing into an Access table that was generatred from data exported from a Word file. Several (about 20-30) fields are from check boxes on the Word form. These fields...
1
by: Kosmos | last post by:
Hey guys, I'm fairly familiar with access by now, but I've never worked with importing text into an access database. I have some fairly large text files (lets say, for example, a folder of 20 text...
1
by: aconti74 | last post by:
Hello I am new to vba programming/coding. I am writing a program that goes through a directory of text files and imports them into the database. The problem is eventually the database gets to big...
0
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
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
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,...
1
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
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
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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
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 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.