Results 1 to 7 of 7
  1. #1
    3 Star Lounger
    Join Date
    Sep 2002
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using Access to populate Word doc. (2k)

    I'm currently using access to populate a word label sheet, using bookmarks on the word doc.

    <font color=red>Dim objWord As Word.Application
    Set objWord = New Word.Application

    Dim CurrentYear As Integer
    Dim BaliffNo As String

    CurrentYear = DLookup("Year", "Options")
    BaliffNo = DLookup("BaliffPhone", "Options")

    Set objWord = CreateObject("Word.Application")

    With objWord

    .Documents.Open ("Cocuments and Settingse79684DesktopCliffLAS.doc")

    .ActiveDocument.Bookmarks("A1").Select
    .Selection.Text = CurrentYear
    </font color=red>

    I have 2 problems.
    In the future, i want it to just print the document straight to the printer, but for the short term, i do want the word document to open.

    At the moment, it does what i want it to do to the document, but kinda locks it up, and it doesn't open. thats 1 problem

    The second problem, is that i want to point a particular object on the labels (there are 10 on a page), to a particular photo.
    the photos are stored as a number on the hard drive, eg: 1.bmp
    so for member 1, i need to insert the 1.bmp into an object placed on the word document.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Using Access to populate Word doc. (2k)

    The line

    Set objWord = CreateObject("Word.Application")

    creates a hidden instance of Word. To make it visible, use

    objWord.Visible = True

    > i need to insert the 1.bmp into an object placed on the word document

    What kind of object? An embedded picture, or a linked picture, or ...?

  3. #3
    3 Star Lounger
    Join Date
    Sep 2002
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using Access to populate Word doc. (2k)

    Yes, its a linked picture..

    the BMP is stored on the hard drive.

    I found this article on microsoft..

    http://support.microsoft.com/kb/124862

    So far, i've managed to get a picture into the first label.. however, i need to move it to the correct location.
    then i have the 10 different photo's to put on the word form. which is laid out as per labels.
    the code being used is:-

    <font color=red>pic = "Cocuments and Settingse79684DesktopCliffPhotos1a.bmp"
    .ActiveDocument.Shapes.AddPicture (pic)
    </font color=red>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Using Access to populate Word doc. (2k)

    You can use something like this:


    Dim rng As Word.Range
    pic = "Cocuments and Settingse79684DesktopCliffPhotos1a.bmp"
    pic = Chr(34) & Replace(pic, "", "") & Chr(34)
    ' Set the location for the picture - a cell, or a bookmark, or whatever you need
    Set rng = .ActiveDocument.Tables(1).Cell(1, 1).Range
    rng.Collapse Direction:=wdCollapseStart
    .ActiveDocument.Fields.Add Range:=rng, Type:=wdFieldIncludePicture, Text:=pic, PreserveFormatting:=False

  5. #5
    3 Star Lounger
    Join Date
    Sep 2002
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using Access to populate Word doc. (2k)

    Thanks hans,, will work on that...

    Do you know a way of referencing the picture ive added directly?

    If i use this code, then the picture i have just added is not always picked up, but a different picture.

    <font color=red>pic = "Cocuments and Settingse79684DesktopCliffPhotos1a.bmp"
    .ActiveDocument.Shapes.AddPicture (pic)
    .ActiveDocument.Shapes(2).Select
    .Selection.ShapeRange.Left = 150
    .Selection.ShapeRange.Top = 30</font color=red>

    Is there a way to make the current selection, the picture i've just added.. ie: something like:-

    <font color=blue>.ActiveDocument.Shapes("0.BMP").Select. </font color=blue>

    I tried this, but it didnt work.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Using Access to populate Word doc. (2k)

    You can use

    Dim shp As Word.Shape
    Set shp = .ActiveDocument.Shapes.AddPicture(pic)
    With shp
    .Left = 150
    .Top = 30
    End With

  7. #7
    3 Star Lounger
    Join Date
    Sep 2002
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using Access to populate Word doc. (2k)

    Perfect.. cheers hans.. will make that another beer. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>


    you know your almost up to a case !

Posting Permissions

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