Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

opening .txt file

Status
Not open for further replies.

kerrigirrl

Programmer
Mar 29, 2001
39
US
is there a way to open a .txt file in access? i'm trying to automate a daily procedure that runs multiple queries, and in the midsts of all these queries, the user needs to check a text file. it'd be sweet if i could open it from within the coding so they didn't have to go searching for it every day. is this possible?
 
From "regular" VB.
FileSystemObject. Add a reference or use OBJECT intead of FileSytemObject, Textstream etc.
Code:
Private Function GetFileIntoString(ByVal strFileName As String) As String
    '*****
    '* Read a file of input into a string.
    '*****
    Dim objTS         As TextStream, _
        objFS           As FileSystemObject
    Dim strResponse     As String
    
    Set objFS = New FileSystemObject
    On Error Resume Next
        ' Open file for Reading, Create=NO, ASCII
        Set objTS = objFS.OpenTextFile(strFileName, ForReading, False, False)
        strResponse = Err.Description
        If Len(strResponse) = 0 Then
            GetFileIntoString = objTS.ReadAll
        End If
        objTS.Close
    On Error GoTo 0
    
    Set objTS = Nothing
    Set objFS = Nothing
    If Len(strResponse) > 0 Then
        Err.Raise vbObjectError + 513, "GetFileIntoString", _
                strFileName & vbCrlf & strResponse
    End If
    
End Function
 

Alternatively, you could open the text file in Notepad or another text reader using the SHELL command.

Dim rv as Integer, filpath As string
filepath = "path\filename"
rv = Shell("notepad.exe " & filepath) Terry
------------------------------------
Blessed is the man who, having nothing to say, abstains from giving us worthy evidence of the fact. -George Eliot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top