Export from active form, then subform.

Steven811

Registered User.
Local time
Today, 10:31
Joined
Apr 18, 2004
Messages
133
Hi

I have the code and it works to export data from an active form to Word. The Form also has 2 subforms and I don't know what code I should be using to move from the end of one form to the next and then perform the same procedure.

The code that I am using successfully is the Microsoft example and is enclosed for info.

I would be grateful for some assistance.

Steven811

Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err

Dim objWord As Word.Application


'Start Microsoft Word.
Set objWord = CreateObject("Word.Application")

With objWord
'Make the application visible.
.Visible = True

'Open the document.
.Documents.Open ("C:\MyMerge.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("DateofComment").Select
.Selection.Text = (CStr(Forms!forProject!DateofComment))

.ActiveDocument.Bookmarks("Comments").Select
.Selection.Text = (CStr(Forms!forProject!Comments))

.ActiveDocument.Bookmarks("Action").Select
.Selection.Text = (CStr(Forms!forProject!Action))

.ActiveDocument.Bookmarks("ActionByDate").Select
.Selection.Text = (CStr(Forms!forProject!ActionByDate))

.ActiveDocument.Bookmarks("ByWhom").Select
.Selection.Text = (CStr(Forms!forProject!ByWhom))



End With

'Print the document in the foreground so Microsoft Word will not close
'until the document finishes printing.
' objWord.ActiveDocument.PrintOut Background:=False

'Close the document without saving changes.
' objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'
' 'Quit Microsoft Word and release the object variable.
' objWord.Quit
' Set objWord = Nothing
' Exit Sub

MergeButton_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
Resume Next
End If

Exit Sub
End Sub
 

Users who are viewing this thread

Back
Top Bottom