Results 1 to 11 of 11
  1. #1
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    84

    Word Automation issue


    Hi all,
    I am doing some Word automation in MS Access in one of my DB's. I am experiencing that MS Word sometimes generates a warning or information message, but the message are being displayed in the back of the database that is open, so the users does not see the message and think that the DB has "freezed" and uses Ctrll + Alt + Del to close Word.
    Once they do this, it is a nightmare to continue doing the automation as Word then displays the message "Word caused a serious error the last time you opened the document....", but because it is displayed at the back of the open DB, the user cannot see the message.

    Is there some way I can force that the message be displayed in front so that it is visible to the users, and they can take appropriate action?


    Thanks a mil.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Is Word document open and visible?

    Why is Word generating message?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    84
    Hi,
    Yes, Word is open and visible in certain instances, and open and not visible in other instances.

    I have no idea why Word is generating the messages.
    The norm seems to be that the document is already open (Word asks if a read only copy must be opened, or the message states that there was an error with the previous opening of the document.

    My big issue is that these messages are not visible to the user as the message is in the background. Once I open the task manager, then only can I see the message. The users do not have access to run the task manager as the DB runs on a remote server.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,574
    Do you have error checking in the code?
    Can you MSGBOX the error code if not taken care of?
    That should appear on top I would have thought?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Post your code.

    Best would be to figure out why messages occur and prevent. Why would user open a document that is already open?

    Not sure the popups can be controlled with code. Seems that would require somehow manipulating Windows.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,822
    Hi

    Try changing it from a Popup to a Normal View.

  7. #7
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    84
    Hi.
    There are no messages in my code. There are error routines that takes care of the errors, should they occur.
    When the automation code runs, I am opening a Word document as a template with no contents. Only the company logo and detail is in the document header.
    I then open some tables in the database and populate the Word document with the data. Once the data is populated, I save a copy of the word document into the user's folder and e-mail the document to the user as well. I then close the Word application.

    When running the next document automation, it seems as if the Access program is in an never-ending loop, but it is not. Word generated messages as described in above discussion. These messages are in the background and not visible to the users. This gives the illusion that the Access program has "freezed".

    I need to tell Word to show the messages in the front (on top of the Access program) so that the user can take the appropriate action and continue, but I am unable to do this.

    Thanks

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Again, provide your code. Could provide db. Might even provide your Word document.

    Is the Access form open in popup mode?

    My comment about manipulating Windows messages not altered by your additional comments.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    DC CS is offline Advanced Beginner
    Windows 11 Office 365
    Join Date
    Jan 2023
    Location
    Vaalpark, South Africa
    Posts
    84
    Hi,
    I am very reluctant to post my code or Word document here as the database is currently running on international level.

    I will post extracts from my code:

    Code:
    Public Function CreateWordLetterETS(strdocpath As String)
    
        
        On Error GoTo errhand1
         
       If IsNull(strdocpath) Or strdocpath = "" Then
          Exit Function
       End If
    
    
       Dim Dbs As Database
       Dim objWord As Object
       Dim objWordDoc As Word.Document
       Dim PrintResponse
       Dim TEMP
       Dim QtyBrokenDays As Double
       Set Dbs = CurrentDb
       Set Dbs1 = CurrentDb
       Set Dbs3 = CurrentDb
       Set Dbs2 = CurrentDb
       Set Dbs4 = CurrentDb
       
       'create reference to Word Object
       QtyBrokenDays = 0
       Set objWord = CreateObject("Word.Application")
       Set objWordDoc = objWord.Documents.Open(strdocpath)
    Code:
       With objWord        .Visible = True
            .Documents.Open (strdocpath)
            .ActiveDocument.Paragraphs(14).Range.Select
            .ActiveDocument.Paragraphs(14).Range.Text = "Competency declaration for"
            .Selection.Paragraphs.Alignment = wdAlignParagraphCenter: .ActiveDocument.Paragraphs.Indent
            .ActiveDocument.Paragraphs(14).Range.Font.Size = 20
            '-----------------------------------------------------------------------------------------
            .ActiveDocument.Paragraphs(15).Range.Select
            .ActiveDocument.Paragraphs(15).Range.Text = Rst1!FirstName & " " & Rst1!Surname
            .Selection.Paragraphs.Alignment = wdAlignParagraphCenter
            '.ActiveDocument.Paragraphs.Indent
            .ActiveDocument.Paragraphs(15).Range.Font.Size = 20
            .ActiveDocument.Paragraphs(15).Range.Font.Color = RGB(0, 0, 0) 'BLACK
            '---------------------------------------------------------------------------------
            .ActiveDocument.Paragraphs(17).Range.Select
            .ActiveDocument.Paragraphs(17).Range.Text = "ID Number"
            .ActiveDocument.Paragraphs(17).Range.Font.Color = RGB(192, 0, 0) 'RED
            .Selection.Paragraphs.Alignment = wdAlignParagraphCenter
            .ActiveDocument.Paragraphs(17).Range.Font.Size = 20
            .ActiveDocument.Paragraphs(18).Range.Select
            .ActiveDocument.Paragraphs(18).Range.Font.Color = RGB(0, 0, 0) 'BLACK
            .ActiveDocument.Paragraphs(18).Range.Font.Size = 20
            .Selection.Paragraphs.Alignment = wdAlignParagraphCenter
    Code:
            .ActiveDocument.Paragraphs(31).Range.Select: .Selection.Paragraphs.Alignment = wdAlignParagraphLeft        .ActiveDocument.Paragraphs(31).Range.Font.Size = 16
            If Format(Rst!CertificateExpDate, "\#dd-mm-yyyy\#") <> Format("31-12-2999", "\#dd-mm-yyyy\#") Then
                .ActiveDocument.Paragraphs(31).Range.Text = Rst!AssDate & Space(77) & Rst!CertificateExpDate
            Else
                .ActiveDocument.Paragraphs(31).Range.Text = Space(2) & Rst!AssDate & Space(81) & "N/A"
            End If
            .ActiveDocument.Paragraphs(31).Range.Font.Color = RGB(0, 0, 0) 'BLACK
            .ActiveDocument.Paragraphs(32).Range.Select
            .ActiveDocument.Paragraphs(32).Range.Font.Size = 10
            .ActiveDocument.Paragraphs(32).Range.Text = "______________________" & Space(107) & "___________________"
            .ActiveDocument.Paragraphs(33).Range.Select: .ActiveDocument.Paragraphs(33).Range.Font.Size = 10
            .ActiveDocument.Paragraphs(33).Range.Font.Size = 16
            .ActiveDocument.Paragraphs(33).Range.Text = "Assessment Date" & Space(68) & "Expiry Date"
            '----------------------------------------------------------------------------------------------------
            .ActiveDocument.Paragraphs.Add: .ActiveDocument.Paragraphs.Add
            .ActiveDocument.Paragraphs(36).Range.Select
            .ActiveDocument.Paragraphs(36).Range.Font.Size = 10
            .ActiveDocument.Paragraphs(36).Range.Text = Space(140) & "____________________________"
            .ActiveDocument.Paragraphs.Add
            .ActiveDocument.Paragraphs(37).Range.Select
            .ActiveDocument.Paragraphs(37).Range.Font.Size = 16
            .ActiveDocument.Paragraphs(37).Range.Text = Space(88) & "Certification Officer"
            .ActiveDocument.Paragraphs(37).Range.Font.Color = RGB(192, 0, 0) 'RED
            'Now save or Update the certificate number
            Rst4.Close
            If Forms!Frm_PrintCertificates.Check9.Value = False Then
                SQL4 = "INSERT INTO Tbl_CertificateNumbers " _
                    & "(CertificateNumberPrefix, CertificateMonthYear, CertificateStudent, CertificateDate, Certificate_ETS_IFSAC, CertificateCertNumber, CertificateStartDate, CertificateEndDate, " _
                    & "CertificatePrinted, CertificateRePrintNo, CertificateRePrintReason, Certificate_IFSAC_SealNumber) " _
                    & "VALUES " _
                    & "(" & NewCertificateNumber & ", " & Format(Date, "mm") + Format(Date, "yyyy") & ", " & Val(Forms!Frm_PrintCertificates.TempID) & ", " & Format(Date, "\#mm-dd-yyyy\#") & ", 'ETS', " _
                    & " " & Val(Forms!Frm_PrintCertificates.CertNo) & ", " & Format(Forms!Frm_PrintCertificates.From, "\#mm-dd-yyyy\#") & ", " & Format(Forms!Frm_PrintCertificates.ToDate, "\#mm-dd-yyyy\#") & ", " _
                    & "True, 0, 'N/A', 'N/A');"
                DoCmd.RunSQL SQL4
            ElseIf Forms!Frm_PrintCertificates.Check9.Value = True Then
    Code:
    'Save the certificate to C:\Temp so that the template does not get overwritten If Not objWord Is Nothing Then
        Dim DocName
        DocName = "C:\Temp\" & UserComputer & "\ID_" & Forms!Frm_PrintCertificates.TempID & "_" & "Course_" & Forms!Frm_PrintCertificates.TmpCourseNo & ".pdf"
        objWordDoc.ExportAsFixedFormat "C:\Temp\" & UserComputer & "\ID_" & Forms!Frm_PrintCertificates.TempID & "_" & "Course_" & Forms!Frm_PrintCertificates.TmpCourseNo & " ETS.pdf", wdExportFormatPDF, False, wdExportOptimizeForPrint, wdExportAllDocument
        MsgBox "The ETS  Certificate has been saved as follows: " & vbCrLf _
            & DocName & ".", vbOKOnly, "Saved as PDF"
        DocName = "C:\Temp\" & UserComputer & "\ID_" & Forms!Frm_PrintCertificates.TempID & "_" & "Course_" & Forms!Frm_PrintCertificates.TmpCourseNo & " ETS.pdf"
     End If
       'release all objects
       objWord.ActiveDocument.Close wdDoNotSaveChanges
       objWord.Application.Quit wdDoNotSaveChanges
       Set objWord = Nothing
       Set Dbs = Nothing
    Rst.Close
    Rst1.Close
    Rst2.Close
    The code runs 100%, but somehow Word generates these messages out of the blu. When this happens, I need the message to be visible to the users.

    Thanks

  10. #10
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  11. #11
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,159
    It sounds as if the Word object isn't being closed correctly for some reason, so that a subsequent run of the code has a orphan process left to deal with.
    You can get very similar weird behaviour with Excel automation.

    It's imperative that the instances are correctly addresses and closed under all circumstances.

    Check in the task manager when you see the random messages for a Word process hanging.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

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

Similar Threads

  1. Word Automation
    By comfygringo in forum Import/Export Data
    Replies: 0
    Last Post: 08-27-2013, 08:49 PM
  2. VBA Grouping via Word Automation
    By besuchanko in forum Programming
    Replies: 5
    Last Post: 03-06-2013, 02:47 PM
  3. Automation to Word Crash
    By besuchanko in forum Programming
    Replies: 5
    Last Post: 03-02-2013, 08:54 PM
  4. Word Automation in Windows 7
    By tmbowden in forum Access
    Replies: 0
    Last Post: 01-23-2012, 01:17 PM
  5. Access and Word Automation
    By djreyrey in forum Forms
    Replies: 1
    Last Post: 01-08-2010, 02:33 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