zocker
08-11-2001, 08:10 AM
I am driving Word from Access, I want to take some text from a form and add a Pic, I've got this code and so far I'm successful except for the insert a Pic bit. I assembled this from recording a macro in Word and re-using (some of) the code. Heres the code I got so far.
Thanks in advance.
Private Sub WordIt_Click()
On Error GoTo Err_WordIt_Click
Dim strAdress As String
Dim strNotes As String
Dim oApp As Object
strAdress = Me!txtAddress
strNotes = Me!txtNotes
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
oApp.CommandBars("Drawing").Visible = True
oApp.Documents.Add Template:="C:\Program Files\Microsoft Office\Templates\Empty.dot",
NewTemplate:=False
'**********
'Some code here inserts Text from an Access form - no probs with that.
'**********
'Dont know why I should have the next line!
oApp.CommandBars("Drawing").Visible = True
'All OK to here now it fails on the next line with the error message "The specified value is out of range" Seems to refer to 'the values
'Have changed values endlessly to find acceptable ones......no dice
oApp.ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 86, 86, 260, 280).Select
oApp.Selection.ShapeRange.TextFrame.TextRange.Select
oApp.Selection.Collapse
oApp.ChangeFileOpenDirectory "C:\My Pictures\"
oApp.Selection.InlineShapes.AddPicture FileName:= _
"C:\My Pictures\20Sep00003.JPG", LinkToFile:=False, SaveWithDocument:= _True
oApp.ActiveDocument.Close SaveChanges:=True
'CloseRunning is a function defined in a module
CloseRunning ("Word")
End Sub
Thanks in advance.
Private Sub WordIt_Click()
On Error GoTo Err_WordIt_Click
Dim strAdress As String
Dim strNotes As String
Dim oApp As Object
strAdress = Me!txtAddress
strNotes = Me!txtNotes
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
oApp.CommandBars("Drawing").Visible = True
oApp.Documents.Add Template:="C:\Program Files\Microsoft Office\Templates\Empty.dot",
NewTemplate:=False
'**********
'Some code here inserts Text from an Access form - no probs with that.
'**********
'Dont know why I should have the next line!
oApp.CommandBars("Drawing").Visible = True
'All OK to here now it fails on the next line with the error message "The specified value is out of range" Seems to refer to 'the values
'Have changed values endlessly to find acceptable ones......no dice
oApp.ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 86, 86, 260, 280).Select
oApp.Selection.ShapeRange.TextFrame.TextRange.Select
oApp.Selection.Collapse
oApp.ChangeFileOpenDirectory "C:\My Pictures\"
oApp.Selection.InlineShapes.AddPicture FileName:= _
"C:\My Pictures\20Sep00003.JPG", LinkToFile:=False, SaveWithDocument:= _True
oApp.ActiveDocument.Close SaveChanges:=True
'CloseRunning is a function defined in a module
CloseRunning ("Word")
End Sub