Word VBA 438 when inserting picture

Fredd
Fredd used Ask the Experts™
on
I'm getting a Run-time error 438 - object doesn't support this property or method.
this only happens like every third or fourth time I run the code
Prior to executing, I'm sure all word instances are shutdown
Environment:  Access 2016 - running VBA to manipulate MS Word 2016 document.
All the references are good I believe (included Word object module, etc)

see attached word file and simple database - see module 1 for sample
it generates a 438 on the line
owordapp.activedocument.content.selection.Goto what:=wdgotobookmark, Name:="photo"
Option Explicit
Sub photoproblem()

Dim owordapp As Object, i As Integer, a As String, v As Shape, rng As range, dir1 As String
Dim template As String, newphoto As String

dir1 = "U:\Data\photoproblem\"
template = dir1 & "SAMPlE FILE.docx"
newphoto = dir1 & "dolphin.png"


Set owordapp = CreateObject("Word.Application")

With owordapp

    .Documents.Open template
    .Visible = True
    .screenupdating = True
    
End With

owordapp.activedocument.content.selection.Goto what:=wdgotobookmark, Name:="photo"

Set rng = selection.range

Set v = activedocument.inlineshapes.addpicture(FileName:=newphoto, range:=rng, savewithdocument:=True).converttoshape

Set rng = Nothing
Set owordapp = Nothing

End Sub

Open in new window

Sample-file.docx
photoproblem1.accdb
dolphin.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Older than dirt
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Did you type
set vshape = activedocument.inlineshapes,addpicture(filename:= filenamestr, range:= rng, savewithdocument:=true).converttoshapre

Open in new window

into your question? If not then there should be a period (full stop) after"inlineshapes" and not a comma.
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You could try adding line 2.
owordapp.activedocument.content.selection.goto what:=wdgotobookmark name:="photo" 
DoEvents

Open in new window

FreddSharePoint Jedi

Author

Commented:
thanks - this is not access but rather word  - I'm inserting into word.  I thought doevents as an access thing.  Also  - it fails onthe goto line - so will never get to the doevents line.
other ideas - you might download the database and try something out perhaps?

also - the comma was a copy/paste error someohow - the code has the properly formatting command. i corrected the question - see dbase for actual code - this code fails right now now everytime so it was working occasionally but not at all.
FreddSharePoint Jedi

Author

Commented:
any help on this?
Martin LissOlder than dirt
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Sorry, but I don't do Access so I can't come up with anything else, but I added Access to your topics in hope that it will attract someone who can.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial