Solved

open on load

Posted on 2007-03-24
5
258 Views
Last Modified: 2010-04-30
hello,
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()
OPEN_NEW:
  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
  LVW.ListItems.Clear
  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
  Wend
  'close and clean up
  TS.Close
  Set TS = Nothing
  Set FSO = Nothing
End Sub
0
Comment
Question by:Sabrin
  • 3
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18784989
AFAIK, App.Path does not contain the trailing \
this should work:
App.Path & "\accounts1.txt"
0
 

Author Comment

by:Sabrin
ID: 18784996
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)
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18785015
and what error does it show (err.description)?
0
 

Author Comment

by:Sabrin
ID: 18785023
runtime error 53
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18785041
that error means: file not found.
please ensure the file is really there (ie the app.path)!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question