Help with vba code (1 Viewer)

kirsty

Registered User.
Local time
Today, 14:12
Joined
Nov 5, 1999
Messages
19
Hi,

I am a bit stuck!! I am trying to write some code in access 97 which uses the on click event procedure of a command button to open a word document.

When the user has finished with the word document I do would like it to be saved as one of the fields on my current record which changes dependng on the record.

I have been trying things like:-
Dim objWord As Word.Application

'Go to Forename control
DoCmd.GoToControl "Forename"

DoCmd.DoMenuItem acFormBar, acEditMenu, acCopy, , acMenuVer70

'Start Microsoft Word 97
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True

'Open the document
.Documents.Open ("S:\FINANCE\RISK\DATABASE\DBletters\merge.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("FIRST").Select
.Selection.Text = (CStr(Forms!Claimform!Forename))
.ActiveDocument.Bookmarks("LAST").Select
.Selection.Text = (CStr(Forms!Claimform!Surname))
.ActiveDocument.Bookmarks("DATE").Select
.Selection.Text = (CStr(Forms!Claimform!Incidentdate))
.ActiveDocument.Bookmarks("REF").Select
.Selection.Text = (CStr(Forms!Claimform!Medclaimno))
End With

'Close the document without saving the changes
objWord.ActiveDocument.SaveAs [Me!Forename]
objWord.Quit
Set objWord = Nothing
Exit Sub

However, it all works apart from the saving bit. PLEASE can anyone help - it is driving me mad!!!

Many thanks in advance,
Kirsty.
 
M

MR B

Guest
Kirsty,

The synatax you need is

Dim StringFileName as String

.
.
.

StringFileName = Trim([Me!Forename])

objWord.ActiveDocument.SaveAs StringFileName
objWord.Quit wdDoNotSaveChanges
Set objWord = Nothing

Best of Luck

Johnb.
 

Users who are viewing this thread

Top Bottom