Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 4th, 2004, 03:07 PM
golfcdigi golfcdigi is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 30 golfcdigi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Question Importing Text into Access Table via VBA

I am relatively new to coding in VBA and am trying to import a text file into a table in Access 2000 using VBA. I am able to open the text file and get the data I need, but am having diffucilty getting the text strings into the table. When I run this code, I get error message "Variable Not Defined" and it stops on the line of code "tblTextFile.AcctNumber = timpAN". I do not know if I am not opening the table correctly or how to "activate" the table to insert the new record to handle the new data. Here is the code I have so far...any help would be greatly appreciated

Function ImportTextFile()
Dim LineData As String
Dim timpAN As String ' Holder for Account Number in text file
Dim timpCT As String ' Holder for the Cusip Number or Ticker Symbol
Dim nimpSH As Double ' Holder for the number of shares held in account
Dim timpLS As String ' Holder for Long or Short Position
Dim nimpVAL As Double ' Holder for value of security
Dim nimpNAV As Double ' Holder for Net Asset Value

' Open the text file
Open "C:\Documents and Settings\User\Desktop\CS060104.txt" For Input As #1
' Open the table to insert the text file into
DoCmd.OpenTable "tblTextFile", acNormal, acEdit

Do While Not EOF(1)
' Read a line of data.
Line Input #1, LineData

timpAN = Left(LineData, 8)
tblTextFile.AcctNumber = timpAN

timpCT = Mid(LineData, 10, 9)
nimpSH = Mid(LineData, 20, 14)
timpLS = Mid(LineData, 35, 1)
nimpVAL = Mid(LineData, 37, 14)
nimpNAV = Mid(LineData, 52, 9)
Loop

' Close the data file.
Close #1

End Function

Reply With Quote
  #2  
Old June 4th, 2004, 09:12 PM
beercraft_asp's Avatar
beercraft_asp beercraft_asp is offline
Spell Breaker
ASP Free Novice (500 - 999 posts)
 
Join Date: May 2004
Posts: 990 beercraft_asp User rank is Lance Corporal (50 - 100 Reputation Level)beercraft_asp User rank is Lance Corporal (50 - 100 Reputation Level)beercraft_asp User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 8 h 33 m 42 sec
Reputation Power: 6
Send a message via AIM to beercraft_asp Send a message via MSN to beercraft_asp
Arrow

Is this will be on going process for you of it just one time thing.

If it's one time

you can just import data from text file into Access 2000 without coding.

Reply With Quote
  #3  
Old June 6th, 2004, 07:39 PM
golfcdigi golfcdigi is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 30 golfcdigi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
This is just the beginning process of creating multiple import routines. Most of the other text files that I will be importing are not in a perfect delimited or fixed width format...so I will need code to extract the exact data I need and then get that data into a database. Any help would be apprecitated. Thanks.

Reply With Quote
  #4  
Old June 8th, 2004, 06:24 PM
dfinnie@excite. dfinnie@excite. is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 dfinnie@excite. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Using ADO methods to add data

I took your program and modifed it for my purposes. You can look at the
program to see how I added the data to the tables. I used the subroutine,
and it added the data as expected.I hope this is helpful.

Don

Sub ImportTextFile()
Dim LineData As String
Dim ICDraw As String ' Holder for Account Number in text file
Dim ICDDesc As String ' Holder for the Cusip Number or Ticker Symbol
Set cncurrent = CurrentProject.Connection
Set rsDiag = New ADODB.Recordset
' Open the text file
Open "F:\Documents and Settings\DFinnie\Desktop\v21icd9_diag.txt" For Input As #1
' Open the table to insert the text file into
strsql = "Select * from tblICD9"
rsDiag.Open strsql, cncurrent, adOpenDynamic, adLockOptimistic
Do While Not EOF(1)
' Read a line of data.
Line Input #1, LineData
ICDraw = Trim(Left(LineData, 6))
ICDDesc = Trim(Mid(LineData, 7))

rsDiag.AddNew
rsDiag!ICD9raw = ICDraw
rsDiag!Description = ICDDesc
rsDiag.Update

Loop
' Close the data file.
Close #1
rsDiag.Close
End Sub

Reply With Quote
  #5  
Old June 9th, 2004, 11:55 AM
golfcdigi golfcdigi is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 30 golfcdigi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Thank You!!!

Reply With Quote
  #6  
Old April 10th, 2009, 10:47 AM
dwiese dwiese is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 2 dwiese User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 47 m 56 sec
Reputation Power: 0
Text to import

This is a sample of 1 of 3000, text files I have to import into Access. The data string always begins with S and subsequent lines in that data string begin with C. Every new line of data begins with S. The "S" and "C" are not part of the data only delimeters. The first 8 characters are part of a series of numbers that is a date i.e 1881121511A. format YYYYMMDD,=SurveyDate the next characters tell what kind of data elements it is "1" = Orginal Survey, 2= Retracement..etc this numeric value can change from 1-9, for various other kinds of surveys=SurveyKind. The next character "1", idenifies an angency 1= BLM, 2= NFS and so on 1-9 values=Agency. The alpha character at the end of the series of number indentifies the first survey "A" and second survey "B" etc.=SurveyID. I'm familiuar enough with parsing out values from a string into different field using 'mid(string,1,1)", but I know absolutly nothing about VB programming to get each of the element into the correct fields. Each of the subsequent strings are elements need to be places in single fields. .100 35000.0 35000. = Realiablity_Factors, GLO-UT= Source_Agnecy, SUBERT, F = Surveryor, 18820428 is another date "YYYYMMDD" = ApprovalDate , and SOUTH PORTION INTERIOR = Comments. I'm importing these text file into a table that already exists, "Twp_Sids.tlb"

This is the sample of the text files

S1881121511A .100 35000.0 35000.0
C GLO-UT
C SUBERT,F
C 18820428
C SOUTH PORTION INTERIOR
S1886081111A .100 35000.0 30000.0
C USGLO
C SALOMON,OE
C 18911031
C NORTH PORTION OF THE SUBDIVISION
S1886080531A .100 35000.0 35000.0
C USGLO
C SALOMON,OE
C 18911031
C INTERIOR LINES OF THE SUBDIVISION
S1894063031A .100100000.0100000.0
C USGLO
C GORLINSKI,R
C 18951123
C NORTH TWO MILES OF THE WEST BOUNDARY
S1884061631A .100 25000.0 25000.0
C USGLO
C KOEBER,EW
C 18840726
C SOUTH FOUR MILES OF THE WEST BOUNDARY
S1881083011A .100 25000.0 15000.0
C USGLO
C SUBERT,F
C 18820428
C EAST BOUNDARY

Any help will be appreciated

Reply With Quote
  #7  
Old April 21st, 2009, 06:08 AM
Darkosa Darkosa is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 14 Darkosa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 34 m 49 sec
Reputation Power: 0
Help With this one

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open MM_ConCompare_STRING
objRecordSet.Open "SELECT * FROM ADInfo", objConnection, adOpenStatic, adLockOptimistic
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set folder = objFSO.GetFolder("C:\Inetpub\wwwroot\Compare\ADUploadedFiles\")
for each file in folder.Files
if lcase(objFSO.getExtensionName(file.path))="txt" then
Set testfile = objFSO.OpenTextFile(file.path, ForReading)
Do While Not testfile.AtEndOfStream
strImport = testfile.ReadLine
arrImport = Split(strImport, ",")
objRecordSet.AddNew
objRecordSet("test") = arrImport(0)
objRecordSet("firstname") = arrImport(1)
objRecordSet("surname") = arrImport(2)
objRecordSet("username") = arrImport(3)
objRecordSet("department") = arrImport(4)
objRecordSet("extension") = arrImport(5)
objRecordSet.Update
Loop
end if
testfile.close
next
objRecordSet.Close
objConnection.Close

I get the following error:

Microsoft VBScript runtime (0x800A0009)
Subscript out of range: '[number: 1]'

Here : objRecordSet("firstname") = arrImport(1)

Any Ideas

Reply With Quote
  #8  
Old June 11th, 2009, 10:23 AM
miscade miscade is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 1 miscade User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 49 sec
Reputation Power: 0
Arrow

Hi guys,

have a similar need, even little bit different. Let's see if you can help me, would be great because I'm in trouble with the following:

I have a Table in a DB
I have a text file to be imported inside this Table
I have the Import Specification rule scheme in order to make the Import in right way

Currently I do this manually, by importing external data, chose the text file, specify the Import Specification rules.

I Need to make this automated via VBA or Macro

Do you have a example code, or links to be checked?

Thanks in advance.
Edo

Reply With Quote
  #9  
Old June 13th, 2009, 06:36 PM
June7 June7 is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2009
Location: The Great Land
Posts: 536 June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 13 h 58 m 7 sec
Reputation Power: 124
One of the suggestions posted should be adaptable to your situation. Darkosa utilized the Split function which has an argument to specify the delimiter character. This may be the best option for you.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > Importing Text into Access Table via VBA


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek