Pass control name from Access to Word

P

Peter Stone

Novice Access 2003, XP

I am on a subform that opens a document in MS Word and renames it.

The user then enters or adds text to the document. When they close Word, I
want to save the text that was entered in Word into a memo field in Access.

I don't know how to pass the control name to MS Word and then save the text
to that control.

I don't want to use the mainform name so that the subform can be used in
multiple main forms.

***Here's the control:

frmMain!fsubPub1.Form!txtPub1

***Here's the code on the command button on the subform:

Private Sub cmdOpenPub1_Click()
On Error GoTo Err_cmdOpenPub1_Click

Dim oWord As Object
Dim oDoc As Object

'Create the Word application object
Set oWord = CreateObject("Word.Application")

If Me!txtPubLnk1 = "C:\t2hDoc\StartHere.Doc" Then
'Open a new document
Set oDoc = oWord.Documents.Add("C:\t2hDoc\StartHere.doc")

'Rename and save the new document
oWord.ActiveDocument.SaveAs Filename:="C:\t2hDoc\Folder\Another
Folder\etc.\" _
& Me.Parent!txtHd.Value & "_" & "Main".doc"

'Store the link to the new document
Me!txtPubLnk1 = "C:\t2hDoc\Folder\Another Folder\etc.\"
& Me.Parent!txtHd.Value & "_" & "Main".doc"
Me.Requery

Else
'Open the existing document
Set oDoc = oWord.Documents.Open(Me!txtPubLnk1.Value)
End If

'Display MS-Word and release the document object
oWord.Visible = True
Set oWord = Nothing

Exit_cmdOpenPub1_Click:
Exit Sub

Err_cmdOpenPub1_Click:
MsgBox Err.Description
Resume Exit_cmdOpenPub1_Click

End Sub

***Here's the code in MS Word that selects and copies the text:

Private Sub Document_Close()

Selection.WholeStory
Selection.Copy

End Sub

Thank you
Peter
 

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