controlling word from access

A

Apples76

i am trying to automate emailing a word form using vb in access.
it looks like i have the open and email side working but i am not able to
'save as'
could someone look at the code and advise please.

also i will need to assign a file name based on several fields joined
together, could someone please be able ot advise?

extract from code

Set WordObj = GetObject(, "Word.Application")
WordObj.Visible = True
WordObj.documents.Open "C:\Access info\planning_form_email_v1.0.Doc", ,
, True
WordObj.SaveAs ("C:\Access info\forms\planningform.doc")
WordObj.Options.SendMailAttach = True
WordObj.ActiveDocument.SendMail
 
S

strive4peace

Do you already have a filed called
"C:\Access info\forms\planningform.doc"
?

If so, you will need to delete it first...

'~~~~~~~~~~~~~~~~~`
dim mFilename as string
mFilename = "C:\Access info\forms\planningform.doc"
if len(Dir(mFilename)) > 0 then
Kill mFilename
end if
'~~~~~~~~~~~~~~~~~`

do you have a path called
"C:\Access info\forms"
?

If not, you will have to create ie first

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MakeAPath

Function MakeAPath( _
pPath As String _
) As Boolean

MakeAPath = False

If Len(Dir(pPath, vbDirectory)) > 0 Then
'directory is already there
MakeAPath = True
GoTo Proc_Exit
End If

Dim i As Integer _
, mPos As Integer _
, mStr As String

mPos = 1
If Right(pPath, 1) <> "\" Then pPath = pPath & "\"

mPos = InStr(mPos, pPath, "\")

Do While mPos > 0
mStr = Left(pPath, mPos)
If Len(Dir(pPath, vbDirectory)) = 0 Then
On Error Resume Next
MkDir mStr
End If
mPos = InStr(mPos + 1, pPath, "\")
Loop

If Len(Dir(pPath, vbDirectory)) > 0 Then
MakeAPath = True
GoTo Proc_Exit
End If

MsgBox "Could not make path: " _
& pPath _
, , "Error making " _
& " directory"

Proc_Exit:
Exit Function


End Function
'~~~~~~~~~~~~~~~~~`


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
A

Apples76

Strive4peace,

could you please expand on the file name part of the code. i have a field
called 'filename' which i can pick the name of the file from. how can i
insert it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top