I want to insert a small graphic image into a a book mark query I prepare in access

atrium

Registered User.
Local time
Tomorrow, 05:03
Joined
May 13, 2014
Messages
348
I have a series of Yes/No fields in a table and I need to insert a tick box image either on or off and merged into a word document performed in access.

This is what I started with but soon realised it want work - any ideas on how I can do it PLEASE


Code:
 IIf([PAYGOT]=True,[tickBox15x14.jpg],[blankTickBox15x14.jpg])
 
Last edited:
This is the code I have created to move the image in to the bookmark position.


Code:
        If oWordDoc.Bookmarks.Exists("BM157") = True Then
                  Set Rng = oWordDoc.Bookmarks("BM157").Range
                  Rng.Collapse
                  If strBookmarkValue = -1 Then
                     sImageFilename = "tickBox15x14.jpg"
                  Else
                     sImageFilename = "blankTickBox15x14.jpg"
                  End If
                  Set shp = oWordDoc.InlineShapes.AddPicture(FileName:=sImagesPath & "\" & sImageFilename, SaveWithDocument:=True, Range:=Rng).ConvertToShape
                  With shp
                    .LockAspectRatio = True
                    .left = 0  'CentimetersToPoints(0)
                    .Top = 0   'CentimetersToPoints(0)
                    .width = 15    'CentimetersToPoints(2.5)
                    .WrapFormat.Type = wdWrapFront
                  End With
           End If

I get an error 13 type mismatch error on the 2nd line. The Merge has gone through and it's now looking at putting in the images.
BM157 = -1

Can anyone tell me why I get an error on the Set Rng = oWordDoc.Bookmarks("BM157").Range
 
Last edited:
hi @atrium

how is Rng declared?

Where and what is your Dim statement?

it should be something like this:
Rich (BB code):
Dim Rng As Range  'Object if late-binding
 
Instead of looking for an image to insert, look into making a small text box with WingDings2 font, using character 0x050. That's a check box. You can scale it by changing font size and can place it using centering, both horizontal and vertical.
 
adding on ... you can use Unicode, and then you don't even have to change the font

Rich (BB code):
   Rng.Text = ChrW(9744)  'Checkbox open ☐
   Rng.Text = ChrW(9745)  'Checkbox checked ☑
   Rng.Text = ChrW(9746)  'Checkbox checked ☒ 

and, in that case, you don't need a range object either!

Rich (BB code):
oWordDoc.Bookmarks("BM157").Range.Text = ChrW(9745)
 
Last edited:
and, you could probably skip the bookmarks too! Just search and replace 0 and -1 ...

Rich (BB code):
Sub ReplaceWithCheckboxes() 
   With ActiveDocument.Range.Find 
      .Text =  "0"
      .Replacement.Text = ChrW(9744) 
      .MatchWholeWord = True 
      .Execute Replace:=2   'wdReplaceAll
      .Text =  "-1"
      .Replacement.Text = ChrW(9745) 
      .MatchWholeWord = True 
      .Execute Replace:=2   'wdReplaceAll
   End With 
   MsgBox  "done"
End Sub

It wouldn't have to be the whole document -- but that might work for you ;)
 
Last edited:
Thank you everyone for your input, much appreciated.
I have used strive4peace's idea. It does exactly what I need
 

Users who are viewing this thread

Back
Top Bottom