Run time error 5981 when trying to create MS Word doc files from Access

Marchese Il Chihuahua

I have created an MS word document which is aimed at downloading field values from a table (query) and creating a report for each record within the table and saving it in a specified directory. Unfortunately, after trying everything, i continue to get the error 5981 (Impossibile to open the memory macro). I am almost positive that all of the code is fine. Below is my code. Any help will be greatly appreciated. Thanks

Public Sub LetteraPromossi()


  Dim rstStudentiPromossi As New ADODB.Recordset
  Dim appWord As New Word.Application
  Dim strPercorso As String
  strPercorso = Application.CurrentProject.Path & "\"
  Const conPercorso As String = "C:\Users\Andrew\Documents\Andrea Lenti\MS Access\eserciziVBAAccess2010\"

  DoCmd.SetWarnings (False)
  'Esegui le query di aggiornamento che sostituiscono i campi Null con ""

  DoCmd.OpenQuery "qryEliminaNulliDaIndirizzo"
  DoCmd.OpenQuery "qryEliminaNulliDaCittà"
  DoCmd.OpenQuery "qryEliminaNulliDaCAP"
  DoCmd.OpenQuery "qryEliminaNulliDaProvincia"

  DoCmd.SetWarnings (True)


  rstStudentiPromossi.Open "qryStudentiPromossi", _
                            CurrentProject.Connection, adOpenForwardOnly

  Do Until rstStudentiPromossi.EOF

      With appWord
        .Documents.Add strPercorso & "comunicazioni.dotx"
        .Selection.Goto wdGoToBookmark, Name:="studente"
        .Selection.TypeText rstStudentiPromossi!Nome & _
        " " & rstStudentiPromossi!Cognome
        .Selection.Goto wdGoToBookmark, Name:="Indirizzo"
        .Selection.TypeText rstStudentiPromossi!Indirizzo
        .Selection.Goto wdGoToBookmark, Name:="Città"
        .Selection.TypeText rstStudentiPromossi!Città
        .Selection.Goto wdGoToBookmark, Name:="CAP"
        .Selection.TypeText rstStudentiPromossi!CAP
        .Selection.Goto wdGoToBookmark, Name:="provincia"
        .Selection.TypeText rstStudentiPromossi!Provincia
        .Selection.Goto wdGoToBookmark, Name:="Media"
        .Selection.TypeText rstStudentiPromossi!Media
        .Visible = True
      End With
      rstStudentiPromossi.MoveNext
  Loop
  rstStudentiPromossi.Close
  Set rstStudentiPromossi = Nothing
End Sub 
pteranodon

It doesn't look like you ever save or close the Word documents -- 1 for every record in the recordset. There is a limit to how many documents you can have open at the same time before running out of memory. I can't tell how many records you are dealing with, but you'll probably want to save and close them within the loop to free up memory for the next one.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error when trying to run Create Extension postgis

From Dev

Run time error 5981 when trying to create MS Word doc files from Access

From Dev

Error when trying to use to "Insert into" a ms-access database

From Dev

Can't debug MS Access 2013 Run-time Error 91

From Dev

VB Excel - When opening a word doc from VB with Excel I get a 'Variable not defined' error when trying to use ActiveDocument

From Dev

Error when trying to run carthage

From Dev

Application freezes when trying to read Author from .doc multiple files

From Dev

Access denied when trying to run stored procedure on MS SQL Server

From Dev

"_OBJC_CLASS_$_" referenced from error xcode when trying to access subproject files

From Dev

Error when trying to access OneDrive root from UWP

From Dev

Batch Convert OpenOffice (ODT) to MS Word (DOC) files?

From Dev

Error when trying to extract files from a zip file

From Dev

VB Excel - When opening a word doc from VB with Excel I get a 'Variable not defined' error when trying to use ActiveDocument

From Dev

Run-time error 13: Type Mismatch in VBA when trying to call function from another workbook

From Dev

How to programmatically create MS Office .doc or .docx files on a linux server

From Dev

500 error when trying to list files from Drive with query parameter

From Dev

"Access Denied" when trying to run a file that contains ".doc" in the filename

From Dev

Variables in MS Word doc

From Dev

Get access to MS Word macros from PHP

From Dev

Adding Notes to MS Word Doc

From Dev

Access denied when trying to run stored procedure on MS SQL Server

From Dev

Error when saving word doc C#

From Dev

Run time error 424 when overwriting spreadsheet from Access VBA

From Dev

VBA Run-time error 1004: Method Range of object _Global failed when trying to create tables in Excel 2013

From Dev

MS-Access 2007 query run-time error

From Dev

ACCESS keeping giving me a syntax error, when trying to create a view

From Dev

Error `object required` while trying to run MS Access queries in Excel VBA

From Dev

Is it possible to edit MS word doc files with Python?

From Dev

I am trying to add data from word doc to access database but it give me operator missing syntax

Related Related

  1. 1

    Error when trying to run Create Extension postgis

  2. 2

    Run time error 5981 when trying to create MS Word doc files from Access

  3. 3

    Error when trying to use to "Insert into" a ms-access database

  4. 4

    Can't debug MS Access 2013 Run-time Error 91

  5. 5

    VB Excel - When opening a word doc from VB with Excel I get a 'Variable not defined' error when trying to use ActiveDocument

  6. 6

    Error when trying to run carthage

  7. 7

    Application freezes when trying to read Author from .doc multiple files

  8. 8

    Access denied when trying to run stored procedure on MS SQL Server

  9. 9

    "_OBJC_CLASS_$_" referenced from error xcode when trying to access subproject files

  10. 10

    Error when trying to access OneDrive root from UWP

  11. 11

    Batch Convert OpenOffice (ODT) to MS Word (DOC) files?

  12. 12

    Error when trying to extract files from a zip file

  13. 13

    VB Excel - When opening a word doc from VB with Excel I get a 'Variable not defined' error when trying to use ActiveDocument

  14. 14

    Run-time error 13: Type Mismatch in VBA when trying to call function from another workbook

  15. 15

    How to programmatically create MS Office .doc or .docx files on a linux server

  16. 16

    500 error when trying to list files from Drive with query parameter

  17. 17

    "Access Denied" when trying to run a file that contains ".doc" in the filename

  18. 18

    Variables in MS Word doc

  19. 19

    Get access to MS Word macros from PHP

  20. 20

    Adding Notes to MS Word Doc

  21. 21

    Access denied when trying to run stored procedure on MS SQL Server

  22. 22

    Error when saving word doc C#

  23. 23

    Run time error 424 when overwriting spreadsheet from Access VBA

  24. 24

    VBA Run-time error 1004: Method Range of object _Global failed when trying to create tables in Excel 2013

  25. 25

    MS-Access 2007 query run-time error

  26. 26

    ACCESS keeping giving me a syntax error, when trying to create a view

  27. 27

    Error `object required` while trying to run MS Access queries in Excel VBA

  28. 28

    Is it possible to edit MS word doc files with Python?

  29. 29

    I am trying to add data from word doc to access database but it give me operator missing syntax

HotTag

Archive