P
Peter Stone
Access 2003, XP
I am on a subform that opens a document in MS Word and renames it.
When Word is closing, 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
I am on a subform that opens a document in MS Word and renames it.
When Word is closing, 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