Unanswered: Open a Text Files through vb in Access
I am trying to open a text file through a click of a button from my access form. At first I attempted to write the content of the text file to a text box located in a separate window which opens in popup format when clicking the button in question. I used streamreader for that but did not succeed. For one I was not sure how/where to add the streamreader to the form as an IO object. I would be happy with just opening the text file in word from the my acccess form...
If you want to read/write from a text file, have a look at File System Objects. I'm assuming you'll need to pick the text file as well, so have a look at the Common Dialog API. If you just want to open a file in Word, have a look here.
Try using the SHELL command, or even better, the access file API.
When I need to do this, I use code such as StartDoc(PathToFile). It doesn't matter what that path is, could be an excel file or a word doc, jpg, whatever.
You just need the following API (I can't remember where I got this, sorry):
'sets up the use of API for opening files.
Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal Hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long
Global Const SW_SHOWNORMAL = 1
Function StartDoc(DocName As String)
'this uses the ShellExecute function to open a file.
On Error GoTo StartDoc_Error
StartDoc = ShellExecute(Application.hWndAccessApp, "Open", DocName, "", "C:\", SW_SHOWNORMAL)
MsgBox "Error: " & Err & " " & Error