473,769 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question on Importing text data to Access

Hi,
I'm trying to get MS Access 2000 to automatically import a series of
(~200) flat text, tab delimited, data files into a single Access table,
with consistent fields and rows.
The files have different, but somewhat logical naming structures
(ex.Jun01.txt, Jun02.txt, Jul01.txt, etc...).

Is there a relatively simple way to accomplish this, considering i'm new
to Access. I was especially hoping to do this without having to
manually create new import specs or type in file names for each new data
file i need to import. With 200-300 files, that can get tedious.

I tried the following code i found on the internet (listed below) which
i created as a module and then run it under a Macro with the OpenModule
action. But i keep getting error message which says that i'm invoking an
invalid outside procedure.

Thanks for any help !

Code:

Dim objAccess
Dim strPathToMDB
Dim sTable
Dim sFilePath

Const acImportDelim = 0

' // NOTE: User must edit variables in this section //
'
' The following 3 lines of code are the only variables
' that need be edited
' Provide paths to the Access MDB, Text file for import
' and the new table name.
'
strPathToMDB = "C:\DbTest. mdb"
sFilePath = "C:\Attachments .txt"
sTable = "Attach"
'
' /////////////////////////////////////////////////////

' Create Access 97 Application Object
Set objAccess = CreateObject("A ccess.Applicati on.8")

' For Access 2000, use Application.9
'Set objAccess = CreateObject("A ccess.Applicati on.9")

' Open the desired database
objAccess.OpenC urrentDatabase( strPathToMDB)

' Use the TransferText command to import the file
' (with Column Heads)
objAccess.DoCmd .TransferText acImportDelim,, sTable,sFilePat h,True

' Clean up
Set objAccess = Nothing
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
1 2802
If the files all have the same structure, you would not need a different
import spec for each one: just use the same spec. (If they are all
different, you don't have to use an import spec.)

Use Dir() in a loop to read the names of all the files in a loop.
Use DoCmd.TransferT ext to import each file.

You don't need CreateObject if you are running the code in Access, and
importing into the existing database. The basic idea will be:

Function ImportFiles()
Dim strPath As String
Dim strFile As String

strPath = "C:\MyFolde r\"
strFile = Dir$(strPath & "*.txt")
Do While Len(strFile) > 0
DoCmd.TransferT ext acImportDelim, "MySpec", "MyTable", strPath &
strFile
strFile = Dir$
Loop
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"D Mat" <da*******@hotm ail.com> wrote in message
news:3f******** *************@n ews.frii.net...
Hi,
I'm trying to get MS Access 2000 to automatically import a series of
(~200) flat text, tab delimited, data files into a single Access table,
with consistent fields and rows.
The files have different, but somewhat logical naming structures
(ex.Jun01.txt, Jun02.txt, Jul01.txt, etc...).

Is there a relatively simple way to accomplish this, considering i'm new
to Access. I was especially hoping to do this without having to
manually create new import specs or type in file names for each new data
file i need to import. With 200-300 files, that can get tedious.

I tried the following code i found on the internet (listed below) which
i created as a module and then run it under a Macro with the OpenModule
action. But i keep getting error message which says that i'm invoking an
invalid outside procedure.

Thanks for any help !

Code:

Dim objAccess
Dim strPathToMDB
Dim sTable
Dim sFilePath

Const acImportDelim = 0

' // NOTE: User must edit variables in this section //
'
' The following 3 lines of code are the only variables
' that need be edited
' Provide paths to the Access MDB, Text file for import
' and the new table name.
'
strPathToMDB = "C:\DbTest. mdb"
sFilePath = "C:\Attachments .txt"
sTable = "Attach"
'
' /////////////////////////////////////////////////////

' Create Access 97 Application Object
Set objAccess = CreateObject("A ccess.Applicati on.8")

' For Access 2000, use Application.9
'Set objAccess = CreateObject("A ccess.Applicati on.9")

' Open the desired database
objAccess.OpenC urrentDatabase( strPathToMDB)

' Use the TransferText command to import the file
' (with Column Heads)
objAccess.DoCmd .TransferText acImportDelim,, sTable,sFilePat h,True

' Clean up
Set objAccess = Nothing

Nov 12 '05 #2

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

Similar topics

11
3418
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 the last field, it only checks the top few 'cells' to see if there is any data, if not, the field is not imported). How do I 'force' Access to import the field, regardless if there is data in the top of the field or not? For instance, I might...
1
6703
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 database stats: Path: C:\Database (contains the database and all the text files to be imported) Text files to import: (SampleData4.txt and SampleData3.txt as testing examples)
1
3679
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 trying to avoid this extra step. can access read in this file directly into a table as append data? thank you very much for any pointers
2
3610
by: nutthatch | last post by:
I want to be able to import an Excel spreadsheet into Access 2K using the macro command Transferspreadsheet. However, the file I am importing (over which I have no control) contains some records that are "dirty" i.e. the field contents do not comply with the expected format (date/time) and they end up in a seperate table of import errors. (The records in "error" are actually empty fields.) This is a regular event and I do not want to...
9
3920
by: jillandgordon | last post by:
I am trying to import an excel file into Access 97. It looks perfectly all right but, every time I try to import it, I get to the lst step and am told that it was not imported due to an error. There is no further explanation. What are the kinds of things that make this happen? Thanks from an obvious rookie. Gordon
17
2029
by: OdAwG | last post by:
Just some questions regarding tables. I am new Access Database and need a little help. I have the following data listed below 01. I have a table called tbl_Customer with the following information listed below 02. In that table I have three columns that have numeric data in it (City, State, Marital_Status) 03. I need to convert the numeric data in table tbl_customer (City, State, Marital_Status) to alpha numeric data 04. using the...
5
3176
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 districts have used the same excel template and populated the same 32 data fields (columns). I created one large excel file from all 49 files which gives me a master table of 60,000 or so records. I have tried to import this master table into access...
1
2863
by: Alan | last post by:
OK this is a weird one. I've got an import routine going whereby name and address data is pulled into a table from a csv file. I'm having strange results when importing postcode/zip data into a text field. I'm also using an import specification that specifies the post/zip code field is text. If the contents of that column are all alphanumeric UK postcodes e.g. LL55
2
2733
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 have either 0 (Not checked) or 1 (Checked). Due to requirements from a third party software application, they HAVE to be either Y(Checked) or N (Not checked) and MUST be a text field in the Access table. I will be importing several thousand of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5298
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
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 we have to send another system
3
2815
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.