Solved

open on load

Posted on 2007-03-24
5
256 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 142

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 142

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 142

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

770 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