Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2006
    Posts
    3

    Unanswered: Transfer Data from Access Subform to Table In Word

    Hi I am wanting to transfer data from both a form and its subform into a premade word document (has to meet company policy so can't really use a report). I can get the data I need from the form but want to know how to get the data from the subform. From what I have tried I can only get the first row of data from the subform to transfer to the word document table. My subform is used for parts used for a repair (part number & description). I have transfered data to date using bookmarks. Can someone please help with how to import the data from the second record and so on into the table on subsequent rows. Thanks. Here is the code I have used for the current data.

    Private Sub Command62_Click()
    On Error GoTo Err_Command62_Click
    Dim oWord As Word.Application
    Dim oDoc As Word.Document
    Dim PathDocu As String

    Set oWord = CreateObject("Word.Application")

    PathDocu = CurrentProject.Path
    Set oDoc = oWord.Documents.Open(PathDocu & "\Writeoff.dot")

    oWord.Visible = True


    'Range.Text expects a string, so we use Nz to convert
    'any Null values into empty strings.
    oDoc.Bookmarks("PartNumber").Range.Text = Nz([ServiceSubform].Form![PartNumber].Value, "")
    oDoc.Bookmarks("Description").Range.Text = Nz([ServiceSubform].Form![Description].Value, "")

    etc.

    Any help on how to invoke the following rows. And if anything needs to be done on the word side (extra bookmarks?)

  2. #2
    Join Date
    Jan 2006
    Posts
    3
    Further to the above. I found on another website that this really should be done from a query instead of a form so I have made a query but I still have a few problems. I have created a bookmark on the second row first column (first row is headings but these don't match the field names) I have managed to get it to paste the query in but it pastes all data into the one cell (including column names and query name which I don't want. Is there a way to get it to copy the query as a table and get it to realise that I am attempting to paste it into an existing table in word. At Current I am using the below code (modified from previous). I believe I probably only need to change one line to get it to paste into the table with the correct formatting. The line which I think needs to be changed is
    oDoc.Bookmarks("wot").Range.Paste (have tried various paste options to no avail.

    Private Sub Command62_Click()
    On Error GoTo Err_Command62_Click
    Dim oWord As Word.Application
    Dim oDoc As Word.Document
    Dim PathDocu As String

    Set oWord = CreateObject("Word.Application")

    PathDocu = CurrentProject.Path
    Set oDoc = oWord.Documents.Open(PathDocu & "\Writeoff.dot")

    oWord.Visible = True

    DoCmd.OpenQuery ("QWriteOffSummary")
    DoCmd.RunCommand acCmdSelectAllRecords
    DoCmd.RunCommand acCmdCopy
    oDoc.Bookmarks("wot").Range.Paste


    Exit Sub

    Err_Command62_Click:
    MsgBox "Error Printing Writeoff Request Form"

    End Sub



    Your help with this one is greatly appreciated.

Posting Permissions

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