Consulting

Results 1 to 5 of 5

Thread: Looking to find out how to create a Word document from Access, NOT mail merge

  1. #1
    VBAX Regular
    Joined
    Jun 2017
    Posts
    6
    Location

    Looking to find out how to create a Word document from Access, NOT mail merge

    I have a weekly report that requires several hours to put together. I've decided to put the data into Access and then use VBA code to put it into a new word document.

    I've searched on how to do this and I keep coming up with nothing or tables. I don't want tables as the paragraphs will be numbers:

    1 2 3, then sub to a b c then sub to i ii iii format.

    The data is coming from 7 different sections within my organization.

    I'd post my code, but the forum keeps telling me it has URL or bad words in it. So I'll attach it, if that works

    I've done something like this for PowerPoint, but when trying the same code here it does not work. again I don't want to add tables as the report has to be in a specific format. I also don't want to do mail merge as each area may have from 3 to 30 different topics for this report when generated.

    Well thanks for you time.
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Your description suggests you're trying to generate some kind of report from Access, in which case you should ask your question in the Access forum: http://www.vbaexpress.com/forum/foru...16-Access-Help
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Regular
    Joined
    Jun 2017
    Posts
    6
    Location
    I'm trying to export data from Access to a new Word document, without using mail merge and not putting the data into a table. Do I still need to post in Access Forum?

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    So use some code to convert the Access report table(s) to text.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Regular
    Joined
    Jun 2017
    Posts
    6
    Location
    Found this code by Daniel Pineault that solved what I needed.

    Set rs1 = db.OpenRecordset("qryDirPriorities", dbOpenDynaset)
      
        With rs1
            If .RecordCount <> 0 Then
                .MoveLast                   'Ensure proper count by moving to last record
                iRecCount = .RecordCount    'Number of records returned by the table/query          ROW
                .MoveFirst                  'Move to first record
                iFldCount = .Fields.Count   'Number of fields/columns returned by the table/query   COLUMS
     
                objWord.ActiveWindow.View.Type = wdPrintView        'Switch to print preview mode (not required just a personal preference)
             Else
                MsgBox "There are no records returned by the specified queries/SQL statement.", vbCritical + vbOKOnly, "No data to generate an Word spreadsheet with"
                GoTo SubError
            End If
        End With
        
        C = 1
            
        While Not rs1.EOF
            For C = 1 To iRecCount
                .TypeText Chr(9) & Chr(9) & FormatRoman(C) & "." & " (U//FOUO) Priority " & Nz(rs1.Fields(0)) & ". " & Nz(rs1.Fields(1))
                .TypeParagraph
                rs1.MoveNext
            Next
        Wend
                    
        rs1.Close
        iRecCount = 0
        iFldCount = 0

Posting Permissions

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