Results 1 to 3 of 3
  1. #1
    bburton is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    15

    Closing Word Document From Access

    Hello!

    I'm having a problem trying to close a word document from my access form with a button.

    Basically my form takes all the data together from a form that is typed in and converts it into a paragraph format by a report that is exported into word where it can all be copied and pasted into the correct location. The users may forget that the Word Document is still open as they continue to process other data and when they click the button it'll error and close down access, losing all data.

    I need the button to close that specific word document before it exports the new one so it can be overwritten without error. As for another kind of approach I've also tried setting errors to false so it just wouldn't close and erase everything if they happened to forget and try again after they do close it, but the error would still show up.



    The runtime error is "3202" by the way if you needed to know.

    This is the basic coding I got for the button right now without the failed codes.



    Code:
    Private Sub Command358_Click()
        
        DoCmd.OutputTo acOutputReport, "Summary New", acFormatRTF, "U:\Administration\DESCRIPTION FORMS\Vehicle Summary.rtf", False
    
        Dim LWordDoc As String
        Dim oApp As Object
    
        'Path to the word document
        LWordDoc = "U:\Administration\DESCRIPTION FORMS\Vehicle Summary.rtf"
    
        If Dir(LWordDoc) = "" Then
            MsgBox "Document not found."
    
        Else
            'Create an instance of MS Word
            Set oApp = CreateObject(Class:="Word.Application")
            oApp.Visible = True
    
            'Open the Document
            oApp.Documents.Open FileName:=LWordDoc
        End If
    End Sub
    Thank you for your help!

  2. #2
    ajetrumpet is offline Banned
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    what is the actual code that's failing??

  3. #3
    bburton is offline Novice
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    15
    Well I have not found a code to try to close the document while it is open, but I tried to turn off error messages so it would not close it forcibly causing data to be lost where they can try again after.

    I basically did something like this


    Code:
    Private Sub Command358_Click()
            
                Application.DisplayAlerts = False
                    
                DoCmd.OutputTo acOutputReport, "Summary New", acFormatRTF, "U:\Administration\DESCRIPTION FORMS\Vehicle Summary.rtf", False
          
                Dim LWordDoc As String
                Dim oApp As Object
    
                'Path to the word document
                LWordDoc = "U:\Administration\DESCRIPTION FORMS\Vehicle Summary.rtf"
    
                If Dir(LWordDoc) = "" Then
                MsgBox "Document not found."
    
                Else
                'Create an instance of MS Word
                Set oApp = CreateObject(Class:="Word.Application")
                oApp.Visible = True
    
                'Open the Document
                oApp.Documents.Open FileName:=LWordDoc
                End If
        
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Import Word document using VBA
    By degras in forum Import/Export Data
    Replies: 4
    Last Post: 04-12-2011, 02:40 AM
  2. Replies: 5
    Last Post: 10-19-2010, 08:02 AM
  3. Open a word document from access
    By natalia in forum Programming
    Replies: 1
    Last Post: 10-13-2010, 08:04 AM
  4. Replies: 5
    Last Post: 07-16-2010, 10:12 AM
  5. Word document INTO Access form
    By jonathonhicks in forum Forms
    Replies: 0
    Last Post: 04-30-2007, 05:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums