Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Import/Export Data

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 09-18-2009, 05:12 AM
Anthony Anthony is offline Windows XP Access 2007 (version 12.0)
Novice
 
Join Date: Sep 2009
Posts: 7
Anthony is on a distinguished road
Default Importing text file into Access Table

Hey everyone. Can anyone help me come up with a script that will allow me to import a text file that's in the format shown below? I'm trying to import each text file field item into a separate field in the database table "Data Archive". For example, the P.O box number which in this case is 105243, would be imported to the box number field in the table. The site number 12 would go into the Site Number field. The transaction code 4101 would go into the Trancode field. And fianlly the volume 00000000000009552 would go into the volume field in the table.

The text file has spaces between each line which is what is giving me a fit. Please look at the file layout and example below. If anyone can help please do.

Text File Layout:

a = Lockbox #: (6) digits and (4) leading spaces. Postions 1 - 10
b = Site ID: (2) digits and (8) leading spaces. Postions 11 - 20
c = ISA #: 10 spaces. Postions 21 - 30. Not used currently
d = Cust #: 5 spaces. Postions 31 - 35. Not used currently
e = RG Key: 11 spaces. Postions 36 - 46. Not used currently
f = Tran Code: (4) digits (4) spaces. Postions 47 - 50
g = Record #: 4 spaces. Postions 51 - 54. Not used currently
h = Count #: 2 Spaces. Postions 55 - 56. Not used currently
i = Volume (17) digits, zero padded to the left of volume. Postions 57-73
j = Dollars (14) digits, zero padded to the left of volume. Postions 74-87
k = Description: 240 spaces. Postions 88 - 327
l = GL #: 23 spaces. Postions 328 - 350
m = Adjustments: 3 spaces. Postions 351 - 353

Text File Example:

105243 12 4101 00000000000009552

105243 12 4102 00000000000000325

105243 12 4108 00000000000043838

105243 12 4110 00000000000043838

105243 12 4205 00000000000000002
Reply With Quote
  #2  
Old 09-18-2009, 08:55 AM
RuralGuy's Avatar
RuralGuy RuralGuy is offline Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,848
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

If you attach a sample of the TextFile maybe someone would create the script for you.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #3  
Old 09-18-2009, 09:08 AM
Anthony Anthony is offline Windows XP Access 2007 (version 12.0)
Novice
 
Join Date: Sep 2009
Posts: 7
Anthony is on a distinguished road
Default

Thanks for Responding. I have the text file but I don't know how to attach it using this forum. How do I do that?
Reply With Quote
  #4  
Old 09-18-2009, 09:16 AM
RuralGuy's Avatar
RuralGuy RuralGuy is offline Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,848
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

Press the Post Reply button and scroll down to the Manage Attachments button.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #5  
Old 09-18-2009, 09:21 AM
Anthony Anthony is offline Windows XP Access 2007 (version 12.0)
Novice
 
Join Date: Sep 2009
Posts: 7
Anthony is on a distinguished road
Default Importing text file into Access Table

Thanks! Here is the text file in question.
Attached Files
File Type: txt ALLCABS.TXT (99.5 KB, 9 views)
Reply With Quote
  #6  
Old 09-18-2009, 09:44 AM
RuralGuy's Avatar
RuralGuy RuralGuy is offline Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,848
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

Is this a one shot deal or will you be doing it repeatedly? Have you already tried the inport wizard as all text fields and then run an update query to trim all of the fields?
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #7  
Old 09-18-2009, 10:48 AM
RuralGuy's Avatar
RuralGuy RuralGuy is offline Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,848
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

This sample db should get you started.
Attached Files
File Type: zip db1.zip (38.3 KB, 14 views)
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #8  
Old 09-18-2009, 11:44 AM
Anthony Anthony is offline Windows XP Access 2007 (version 12.0)
Novice
 
Join Date: Sep 2009
Posts: 7
Anthony is on a distinguished road
Default

Thank you so much!
Reply With Quote
  #9  
Old 09-18-2009, 03:14 PM
RuralGuy's Avatar
RuralGuy RuralGuy is offline Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,848
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

You're welcome. Are you ready to mark this thread as Solved yet?
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #10  
Old 09-23-2009, 10:35 AM
Anthony Anthony is offline Windows XP Access 2007 (version 12.0)
Novice
 
Join Date: Sep 2009
Posts: 7
Anthony is on a distinguished road
Default

Well, I thought that I was ready to close this thing out but I was thrown a curve ball. I had to alter the script to now accomdate a comma delemited text file. Everything works fine except for the fact that my script is skipping the first line in the file. What in the world am I missing that? Here is my script.



filnam = Me![Text2]
Set objFile = CreateObject("Scripting.FileSystemObject")
Set objText = objFile.OpenTextFile(filnam)
Set rs = CurrentDb.OpenRecordset("FlatFileImport")
once = False
If Not IsNull(Me.Text2) Then filnam = Me.Text2
Open filnam For Binary As #1
'Do While Not objText.AtEndOfStream
Do Until objText.AtEndOfStream
strTextLine = objText.Readline
Data = Split(strTextLine, ",")
If once Then
rs.AddNew
rs.Fields(1) = Me.TheSiteID 'Site ID
'rs.Fields(1) = Data(0) 'Site ID
rs.Fields(2) = Data(1) 'Client ID
rs.Fields(3) = Data(2) 'Client Name
rs.Fields(4) = Data(3) 'DDA Account
rs.Fields(5) = Data(4) 'Process Date
rs.Fields(6) = Data(5) 'Good Checks Singles

rs.Update
End If

once = True
MyLine = ""
MyLine = MyLine & ch
MyLocation = Loc(1)
Loop

Close #1 ' Close file.
rs.Close
'close and erase the file from memory
objText.Close
Set objText = Nothing
Set rs = Nothing
Reply With Quote
  #11  
Old 09-23-2009, 11:02 AM
Anthony Anthony is offline Windows XP Access 2007 (version 12.0)
Novice
 
Join Date: Sep 2009
Posts: 7
Anthony is on a distinguished road
Default

Okay, I just figured out what what happening. I had an if statement that was causing the script to skip the file line in the file. Once I removed it everything started working properly. Thanks guys!!
Reply With Quote
  #12  
Old 09-23-2009, 12:33 PM
RuralGuy's Avatar
RuralGuy RuralGuy is offline Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,848
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

Excellent! So this thread is ready for the Solved thread tool right?
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #13  
Old 09-23-2009, 02:32 PM
Anthony Anthony is offline Windows XP Access 2007 (version 12.0)
Novice
 
Join Date: Sep 2009
Posts: 7
Anthony is on a distinguished road
Default

Yep! We can close this puppy out!
Reply With Quote
  #14  
Old 09-23-2009, 02:47 PM
RuralGuy's Avatar
RuralGuy RuralGuy is offline Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,848
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

It's your thread so just follow the link in my sig.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy data from text file into table in access miziri Programming 3 08-12-2009 01:02 PM
Importing Txt file via Vb jquickuk Import/Export Data 1 04-01-2009 06:27 AM
Importing file into Access jquickuk Import/Export Data 1 03-23-2009 07:18 PM
Importing a tab delimited file into access table - please he championss Import/Export Data 0 10-29-2006 12:33 AM
Importing a table created in word to Access anthony_f_justin Access 4 01-04-2006 06:06 AM


All times are GMT -8. The time now is 08:16 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.