My VBA Code for importing text file to access is not working. Following is the Code

Was this post useful to you?

Function comImport_Click()
Dim Linedata As String
Dim Code1 As Integer ' Holder for Account Number in text file
Dim COOMPANIE As String ' Holder for the Cusip Number or Ticker Symbol
Dim Typeop As String ' Holder for the number of shares held in account
Dim MOUNANT As String ' Holder for Long or Short Position
Dim TYPEMOU As String ' Holder for value of security
Dim DATE1 As String ' Holder for Net Asset Value
Dim PRO As String

' Open the text file
Open "C:\Temp\prova.txt" For Input As #1
Do Until EOF(1)
' Open the table to insert the text file into
DoCmd.OpenTable "Table1", acNormal, acEdit

'Do While Not EOF(1)
' Read a line of data.

Line Input #1, Linedata

Companie = Mid(Linedata, 3, 1)
Typeop = Mid(Linedata, 4, 4)
MOUNTANT = Mid(Linedata, 8, 4)
TYPEMOU = Mid(Linedata, 12, 4)
DATE1 = Mid(Linedata, 16, 4)
PRO = Mid(Linedata, 20, 4)
Table1.Fields(1) = Companie
Table1.Fields(2) = Typeop
Table1.Fields(3) = MOUNTANT
Table1.Fields(4) = Typeop
Table1.Fields(5) = DATE1
Table1.Fields(6) = PRO
Loop

' Close the data file.
End Function

!!!!!!!!!!!!! Please Help

bodh26's picture
bodh26
Sun, 08/03/2014 - 10:50

Post your reply

Filtered HTML

  • Allowed HTML tags: <b> <br> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.