Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

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, 02: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: 5
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, 08: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: 5
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, 06: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: 5
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, 05: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, 10: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: 5
Thank You!!!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > 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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway