Bookmarks to export form data

Steven811

Registered User.
Local time
Today, 19:45
Joined
Apr 18, 2004
Messages
133
Hi

I have used the ms example to export the data from a form.

When I run the procedure the word doc opens but the data is not there, just the original bookmarks.

Any suggestions would be great.

Here is the code.

Thanks

Private Sub MergeButton_Click()
On Error GoTo MergeButton_Err

Dim objWord As Word.Application


'Start Microsoft Word 97.
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!Comment))

.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
 
Another solution

Hi Steven

I've done it with another code:

datafield.SetFocus
' Transfer to Word Bookmark
wordApp.documents(1).bookmarks("bookmarkname").range = IIf(IsNull(datafield.Text), "", datafield.Text)

Hope you can use it... :cool:

/Rudy
 
Book marks

[I've done it with another code]

Hi Rudy

Thanks for your reply.

In the mean time I've tinkered with the original code and it works okay now. Do you know how to print using bookmarks from multiple forms?

Regards

Steven811
 
Multiple forms

Hi Rudy

I have a tracking form that I use a lot and I need to print the current record set out on a regular basis. This is made up of:

Parent Form (Customer)
SubForm1 (Site)
Subform2 (Contact)
Subform3 (Job)

With the code I have so far I can print the data from the current form, what I need to able to do is to print the data that is linked to the other form and is showing in the forms at the time I click print.

As you can tell I am an enthusiastic novice

I enclose a screen shot of the form I use, this may explain the situation more easily.

Regards

Steven
 

Attachments

  • ScreenShot.jpg
    ScreenShot.jpg
    73.3 KB · Views: 133

Users who are viewing this thread

Back
Top Bottom