• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

open on load

I would like to have this load once the app is executed in Form_Load
and not in mnuOpen_Click how can i do it ? the file im trying to open is
App.Path & "accounts1.txt"

Private Sub mnuOpen_Click()
  Dim tmpPath As String
  tmpPath = ShowFileDialog(Me.hWnd, stOPEN, "Text Files (*.acc)|*.acc", "Select Tab Delimited File", App.Path)
  If Not tmpPath = "" Then
  LoadFile tmpPath, lvwMain
  End If
frmMain.Caption = "Accounts Currently Added [" & lvwMain.ListItems.Count & "]"
End Sub

Public Sub LoadFile(mPath As String, LVW As ListView)
  'clear any previous items in the listView
  Set FSO = New FileSystemObject
  'open the file for reading
  Set TS = FSO.OpenTextFile(mPath, ForReading, False)
  'cycle through the rest of the file to add the items
  While Not TS.AtEndOfStream
    'split the line into a string array
    tabLine = Split(TS.ReadLine, ":")
    If UBound(tabLine) = 4 Then
        Set lItem = LVW.ListItems.Add(, , tabLine(0))
        For J = 1 To UBound(tabLine)
            lItem.ListSubItems.Add , , tabLine(J)
        Next J
    End If
  'close and clean up
  Set TS = Nothing
  Set FSO = Nothing
End Sub
  • 3
  • 2
1 Solution
Guy Hengel [angelIII / a3]Billing EngineerCommented:
AFAIK, App.Path does not contain the trailing \
this should work:
App.Path & "\accounts1.txt"
SabrinAuthor Commented:
this is what I have but is not working

Private Sub Form_Load()
LoadFile App.Path & "\accounts1.txt", lvwMain
End Sub

when I execute the file it makes this line yellow

  Set TS = FSO.OpenTextFile(mPath, ForReading, False)
Guy Hengel [angelIII / a3]Billing EngineerCommented:
and what error does it show (err.description)?
SabrinAuthor Commented:
runtime error 53
Guy Hengel [angelIII / a3]Billing EngineerCommented:
that error means: file not found.
please ensure the file is really there (ie the app.path)!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now