Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to retain format when merging access data with word.dot

Status
Not open for further replies.

bdm1

Programmer
Feb 4, 2002
75
0
0
US
I have a Word Template which has bookmarks to data from an Access table. Everything works fine except I cannot figure out why the currency format is not retained when the document prints out. I have search the KB articles as this seems to be some MS glitch but have not been able to find a satisfactory answer. Below is the code attached to the merge button on my Access form.

Private Sub MergeButton_Click()

On Error GoTo MergeButton_Err
Dim objWord As Word.Application

' Start Microsoft Word
Set objWord = CreateObject("Word.Application")
With objWord
.Visible = True
' Open the document.
.Documents.Open ("c:\Operations\ITAR.dot")
' Move to each bookmark and insert text from the form
.ActiveDocument.Bookmarks("ProName").Select
.Selection.Text = (CStr(Forms!frmITAR!ProjectName))
.ActiveDocument.Bookmarks("Amount").Select
.Selection.Text = (CStr(Forms!frmITAR!Amount))


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

Else
MsgBox Err.Number & vbCr & Err.Description
End If
Exit Sub
End Sub

I need to retain the currency format. Any suggestions? Thanks much.
 
Change your code to add a format function on those fields you want to export as currency. for example: Format(Field,"$0.00") instead just Field. Hope this helps!
 
How simple!!!I took your suggestion and it worked like a charm!!! Thanks so much...
 
bdm....I am doing something similar to this; merging individual files in Access into Word (several different Word files)....and I am STUMPED! I am still learning code, so I need a little interpretation to the code you provided and perhaps a little advice....can you get in touch with me? mtpgringa@aol.com

thanks! wouldn't bother you except i'm under EXTREME duress on this one....and under deadline, too...can send you file if you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top