Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    37

    Unanswered: Open a Text Files through vb in Access

    Hi

    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...

    simone

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    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.
    Me.Geek = True

  3. #3
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    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):

    Code:
    '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)
        Exit Function
    
    StartDoc_Error:
        MsgBox "Error: " & Err & " " & Error
        Exit Function
    End Function
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  4. #4
    Join Date
    May 2005
    Posts
    1,191
    I think ST might have gotten that from microsoft's site, a little modified. Thanks for the tip ST!
    Me.Geek = True

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    It's quite possible
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •