Solved

open on load

Posted on 2007-03-24
5
254 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]
Comment Utility
AFAIK, App.Path does not contain the trailing \
this should work:
App.Path & "\accounts1.txt"
0
 

Author Comment

by:Sabrin
Comment Utility
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]
Comment Utility
and what error does it show (err.description)?
0
 

Author Comment

by:Sabrin
Comment Utility
runtime error 53
0
 
LVL 142

Accepted Solution

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to the message 13 62
A macro to Count the number of rows across all worksheets 3 63
using Access 8 52
VBA filters 2 37
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 …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now