Click to See Complete Forum and Search --> : Help with opening a file
VBfreak
Jan 25th, 2000, 12:00 AM
If you are hard coding the document's location there shouldn't be any problem but if you can save the document in different places, you should use an .ini file that contains the path that should be read when you click that button. GOOD LUCK
Aaron Young
Jan 25th, 2000, 12:13 AM
How do you want to Open it?
Into your own Text/RTF Box or In an External Program, like Notepad?
External Program..
Private cmdOpen_Click()
'sFileName is the Path and FileName of the Saved File you want to Open with Notepad.
Shell "Notepad.exe " & sFileName
End Sub
Into a Text/RTF Box..
Private Sub cmdOpen_Click()
Dim iFile As Integer
Dim sData As String
iFile = FreeFile
Open "TheFile.txt" For Input As iFile
sData = Input(LOF(iFile), iFile)
Close iFile
Text1 = sData
End Sub
If the File is too big for the Input() Function..
Private Sub cmdOpen_Click()
Dim iFile As Integer
Dim sData As String
Dim sChunk As String
Dim lChunk As Long
Dim lFileLen As Long
iFile = FreeFile
Open "C:\TheFile.txt" For Binary Access Read As iFile
lFileLen = LOF(iFile)
lChunk = 64000
While Loc(iFile) < lFileLen
If Loc(iFile) + lChunk > lFileLen Then lChunk = lFileLen - Loc(iFile)
sChunk = Space(lChunk)
Get #iFile, , sChunk
sData = sData & sChunk
Wend
Close iFile
End Sub
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com
Hi
At present I've got a programme that creates a file and then saves it (according to some name the user has created) on the desktop. What I want is to be able to open the document directly through a command button on the main form, I've tried a couple of different ways but each time I'm creating some sort of error! Any help with opening up the document would be great.
Thanx.
Still can't get the document to open, I've inclosed the code that saves the document.
Public Sub SaveFile(sOutputFile As String)
Dim n As Long
Dim hFile As Long
hFile = FreeFile
Open sOutputFile For Output As #hFile
For n = 1 To UBound(sAllFiles)
Print #hFile, sAllFiles(n)
Next
close hfile
End Sub
What am I doing wrong?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.