473,511 Members | 12,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automated Import TXT file into Access

1 New Member
I try to automated import TXT using macro - but i would like the user to be able to select where the TXT file is or brouse.
Oct 20 '06 #1
15 13356
Killer42
8,435 Recognized Expert Expert
I try to automated import TXT using macro - but i would like the user to be able to select where the TXT file is or brouse.
I did something quite similar in an Access 2003 database, but I don't recall exactly how. It's Saturday afternoon here now, I can check on Monday morning and let you know, if you like.
Oct 21 '06 #2
Zeeshan7
44 New Member
Hi,

Use TransferText action in Macro. Good luck
Oct 23 '06 #3
honuman
2 New Member
Hi,

Use TransferText action in Macro. Good luck
dr PLZ PLZ plz help me to get data from txt file to my access table.
Feb 4 '07 #4
ADezii
8,834 Recognized Expert Expert
I try to automated import TXT using macro - but i would like the user to be able to select where the TXT file is or brouse.
One very neat solution is the use the Microsoft Office FileDialog in conjunction with the TransferText Method. This will give you the complete flexibility that you require.
NOTE: You must first set a Reference to the Microsoft Office XX.0 Object Library
Expand|Select|Wrap|Line Numbers
  1. Dim fDialog As Office.FileDialog
  2. Dim varFile As Variant
  3.  
  4. 'Set up the File Dialog
  5. Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
  6. With fDialog
  7.   .AllowMultiSelect = False
  8.   .Title = "Select a Text File to Import"
  9.   .InitialFileName = "C:\*.txt"
  10.  
  11.   'Clear out any Filters, then Add you own (1)
  12.   .Filters.Add "Text Files", "*.TXT"
  13.  
  14.   'Show the Dialog. If the Show Method returns True, the User picked
  15.   'at least 1 File, otherwise the User clicked Cancel
  16.   If .Show Then
  17.     For Each varFile In .SelectedItems
  18.       'There will be only 1 File selected, so place the proper Arguments into the TransferText Method
  19.       DoCmd.TransferText(TransferType, SpecificationName, TableName, varFile, HasFieldNames, HTMLTableName, CodePage)
  20.     Next
  21.   Else      'Nothing selected in File Dialog
  22.   End If
  23. End With
Feb 4 '07 #5
burgesg
1 New Member
The import code works well excess i get a notify window saying 'You are about to append 1 row(s)' for each record. Has snyone got a suggestion about how to turn this off?
Cheers
Jan 22 '08 #6
PianoMan64
374 Recognized Expert Contributor
in the code type the following near the top

Expand|Select|Wrap|Line Numbers
  1.  
  2.       docmd.setwarnings False
  3.  
Jan 22 '08 #7
ADezii
8,834 Recognized Expert Expert
One very neat solution is the use the Microsoft Office FileDialog in conjunction with the TransferText Method. This will give you the complete flexibility that you require.
NOTE: You must first set a Reference to the Microsoft Office XX.0 Object Library
Expand|Select|Wrap|Line Numbers
  1. Dim fDialog As Office.FileDialog
  2. Dim varFile As Variant
  3.  
  4. 'Set up the File Dialog
  5. Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
  6. With fDialog
  7.   .AllowMultiSelect = False
  8.   .Title = "Select a Text File to Import"
  9.   .InitialFileName = "C:\*.txt"
  10.  
  11.   'Clear out any Filters, then Add you own (1)
  12.   .Filters.Add "Text Files", "*.TXT"
  13.  
  14.   'Show the Dialog. If the Show Method returns True, the User picked
  15.   'at least 1 File, otherwise the User clicked Cancel
  16.   If .Show Then
  17.     For Each varFile In .SelectedItems
  18.       'There will be only 1 File selected, so place the proper Arguments into the TransferText Method
  19.       DoCmd.TransferText(TransferType, SpecificationName, TableName, varFile, HasFieldNames, HTMLTableName, CodePage)
  20.     Next
  21.   Else      'Nothing selected in File Dialog
  22.   End If
  23. End With
Reference Line Numbers 4 and 27
Expand|Select|Wrap|Line Numbers
  1. Dim fDialog As Office.FileDialog
  2. Dim varFile As Variant
  3.  
  4. DoCmd.SetWarnings False
  5.  
  6. 'Set up the File Dialog
  7. Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
  8. With fDialog
  9.   .AllowMultiSelect = False
  10.   .Title = "Select a Text File to Import"
  11.   .InitialFileName = "C:\*.txt"
  12.  
  13.   'Clear out any Filters, then Add you own (1)
  14.   .Filters.Add "Text Files", "*.TXT"
  15.  
  16.   'Show the Dialog. If the Show Method returns True, the User picked
  17.   'at least 1 File, otherwise the User clicked Cancel
  18.   If .Show Then
  19.     For Each varFile In .SelectedItems
  20.       'There will be only 1 File selected, so place the proper Arguments into the TransferText Method
  21.       DoCmd.TransferText(TransferType, SpecificationName, TableName, varFile, HasFieldNames, HTMLTableName, CodePage)
  22.     Next
  23.   Else      'Nothing selected in File Dialog
  24.   End If
  25. End With
  26.  
  27. DoCmd.SetWarnings True
Jan 22 '08 #8
Frank Kelm
3 New Member
I would like to do the same thing, but also have limited skills. Is this code for a sub-routine that I can call from a form or a macro?

Thanks,

Frank
Jan 25 '08 #9
ADezii
8,834 Recognized Expert Expert
I would like to do the same thing, but also have limited skills. Is this code for a sub-routine that I can call from a form or a macro?

Thanks,

Frank
You can call it from the Click() Event of a Command Button, Function Procedure, Sub-Routine Procedure, etc.
Jan 25 '08 #10
Frank Kelm
3 New Member
You can call it from the Click() Event of a Command Button, Function Procedure, Sub-Routine Procedure, etc.
Sorry to be so ignorant, but I've pasted this in to my application as a module.

Is this where it goes?

Thanks,
Jan 28 '08 #11
ADezii
8,834 Recognized Expert Expert
Sorry to be so ignorant, but I've pasted this in to my application as a module.

Is this where it goes?

Thanks,
The easiest solution would be to create a Command Button with the Wizard then copy and Paste this code in the Button's Click() Event.
Jan 28 '08 #12
Frank Kelm
3 New Member
The easiest solution would be to create a Command Button with the Wizard then copy and Paste this code in the Button's Click() Event.

Thanks, I appreciate your help!
Jan 28 '08 #13
ADezii
8,834 Recognized Expert Expert
Thanks, I appreciate your help!
You are quite welcome.
Jan 29 '08 #14
ArnoB
1 New Member
Hello,

I just started to build my first serious Access Database and need your help.

I use the above method and it is working, but I struggle having a really flexible import and also one for more than one file.

I get the ImportText function only working in a way that I can import a specific file named in the TransferText MEthod as File Name, not the selected one.

Finally I would like to know how to import 12 documents, called VLCV1, VLCV2...


This is what I wanna do.


I have 12 documents with 4 columns that give me
Date, Time, Pressure and Temperature

I need to read these documents in and connect them together to get one document that has

Date, Time, Pressure 1, pressure 2... temp1, temp2

The issue is that those 12 documents exist for different days and I want to keep them separated from each other, by at least selecting the right folder and then import the 12 according files, don't need to have all files always in Access.

I have some more questions, but getting the files into Access with the necessary flexibility is my first target.

Appreciate all help and if further explaination is required, please let me know
Nov 9 '08 #15
ADezii
8,834 Recognized Expert Expert
To process Multiple Text Documents, change Line #9 to:
.
Expand|Select|Wrap|Line Numbers
  1. AllowMultiSelect = True
P.S. - You will also need a Method to uniquely Name each Table.
Nov 10 '08 #16

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

Similar topics

9
5792
by: Peter Hansen | last post by:
The term "mock filesystem" refers to code allowing unit or acceptance tests to create, read and write, and manipulate in other ways "virtual" files, without any actual disk access. Everything is...
3
3334
by: Chris | last post by:
I've been researching this on and off for weeks, and haven't come up with anything useful yet. If anyone knows how to do this, please let me know. From a Java applet running in IE 6.0 using the...
1
6683
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...
10
1392
by: david | last post by:
Hi, I have an MS Access app which is split Front / Back. The Back End resides on our server. A seperate copy of the front end also resides on the server, one copy in each of our network users...
3
1321
by: miloann2002 | last post by:
We have a vendor access package and I am adding query and report modules to it. An icon was created to display a popup menu to list these report printing options. The added queries and reports...
5
2498
by: Salad | last post by:
I have a textbox for storing the URL to a web page. I figured the person could simply copy the URL from IE and paste it into the text box. The client would like to have a more automated process. ...
2
9221
by: john | last post by:
I have 400 different Excel-spreadsheetfiles, same structure, all with only one record in it, and all residing in the same folder. Every now and then new Excel files are being added. In my Access...
3
2195
by: derfer | last post by:
I am trying to import a .inf file into access (the file comes from the output of some 3rd party software). I have managed to convert the file by opeing it in notepad and re-saving then a seperate...
2
6620
by: thesti | last post by:
hello, how to programmatically from VB .net / php. to import data from an EXCEL file? is there's no programmatic way, how to automated the process. as i search, the process is: Simply...
0
7356
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
7427
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...
0
5671
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
5069
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
4741
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
3227
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
1577
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 ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
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...

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.