send current record to word with automation

G

Guest

HELP!!!!!

I have an access database program which I am using to send information to
word documents. I used the following function to do this automation but when
I send the data across to the word bookmarks it does not send the input mask
with the numbers (i.e. it should send across LC04-0256-01 but sends 04025601
instead) Is there any way that I can add an input mask to word so that it
displays the correct format or can I add some code to change the format.

Input Mask: "LC"00-0000-00
Format: "LC"@@-@@@@-@@

Function MergeButtonEP_Mw2901()
On Error GoTo MergeButton_Err

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

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

'Open the document.
.Documents.Open ("G:\Data Server\Internal Data\Office
Administration\Lift Directive & ISO 9001\MW Forms\Access MwForms\Erectors
Pack\Mw 29.0.1 - Equipment Checklist.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("JobNo").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrJobNoID]))
.ActiveDocument.Bookmarks("LiftNo").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrLiftNoID]))
.ActiveDocument.Bookmarks("LiftType").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![Erectors Pack
MRL Traction Full Lifts Spec]![chrLiftType]))
.ActiveDocument.Bookmarks("Floors").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![Erectors Pack
MRL Traction Full Lifts Spec]![lngFloors]))
.ActiveDocument.Bookmarks("SiteName").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrJobname]))
.ActiveDocument.Bookmarks("SiteAddress1").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrJobaddress]))
.ActiveDocument.Bookmarks("SiteAddress2").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrJobaddress1]))
.ActiveDocument.Bookmarks("SiteAddress3").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrJobaddress2]))

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 Function

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 Function

End Function
 
V

Van T. Dinh

The easy way is to store the masking characters with the input value. In
you case, you elected not to store the masking characters and hence the
value of the Field is "04025601" and not "LC04-0256-01.

The second part of the InputMask specifies whether the masking characters
are stored as part of the value of the Field. Check Access Help on the
InputMask Property paying particular each part of the InputMask (which has 3
distinct parts).

Alternatively, you can simply re-construct the value inserting the masking
characters like:

"LC" & Left([Fld], 2) & "-" & Mid([Fld], 3, 4) & "-" & Right([Fld], 2)

and use this to set the value of the BookMark in Word.

--
HTH
Van T. Dinh
MVP (Access)


Barry said:
HELP!!!!!

I have an access database program which I am using to send information to
word documents. I used the following function to do this automation but
when
I send the data across to the word bookmarks it does not send the input
mask
with the numbers (i.e. it should send across LC04-0256-01 but sends
04025601
instead) Is there any way that I can add an input mask to word so that it
displays the correct format or can I add some code to change the format.

Input Mask: "LC"00-0000-00
Format: "LC"@@-@@@@-@@

Function MergeButtonEP_Mw2901()
On Error GoTo MergeButton_Err

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

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

'Open the document.
.Documents.Open ("G:\Data Server\Internal Data\Office
Administration\Lift Directive & ISO 9001\MW Forms\Access MwForms\Erectors
Pack\Mw 29.0.1 - Equipment Checklist.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("JobNo").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrJobNoID]))
.ActiveDocument.Bookmarks("LiftNo").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrLiftNoID]))
.ActiveDocument.Bookmarks("LiftType").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![Erectors Pack
MRL Traction Full Lifts Spec]![chrLiftType]))
.ActiveDocument.Bookmarks("Floors").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![Erectors Pack
MRL Traction Full Lifts Spec]![lngFloors]))
.ActiveDocument.Bookmarks("SiteName").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrJobname]))
.ActiveDocument.Bookmarks("SiteAddress1").Select
.Selection.Text = (CStr(Forms![Erectors Pack
Form]![chrJobaddress]))
.ActiveDocument.Bookmarks("SiteAddress2").Select
.Selection.Text = (CStr(Forms![Erectors Pack
Form]![chrJobaddress1]))
.ActiveDocument.Bookmarks("SiteAddress3").Select
.Selection.Text = (CStr(Forms![Erectors Pack
Form]![chrJobaddress2]))

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 Function

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 Function

End Function
 
D

David Lloyd

Barry:

One option is to reformat the value before sending it to Word. For example:

"LC" & Left("04025601",2) & "-" & Mid("04025601",3,4) & "-" &
Right("04025601",2)

You can replace the "04025601" value with the value of the appropriate form
field.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


HELP!!!!!

I have an access database program which I am using to send information to
word documents. I used the following function to do this automation but when
I send the data across to the word bookmarks it does not send the input mask
with the numbers (i.e. it should send across LC04-0256-01 but sends 04025601
instead) Is there any way that I can add an input mask to word so that it
displays the correct format or can I add some code to change the format.

Input Mask: "LC"00-0000-00
Format: "LC"@@-@@@@-@@

Function MergeButtonEP_Mw2901()
On Error GoTo MergeButton_Err

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

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

'Open the document.
.Documents.Open ("G:\Data Server\Internal Data\Office
Administration\Lift Directive & ISO 9001\MW Forms\Access MwForms\Erectors
Pack\Mw 29.0.1 - Equipment Checklist.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("JobNo").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrJobNoID]))
.ActiveDocument.Bookmarks("LiftNo").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrLiftNoID]))
.ActiveDocument.Bookmarks("LiftType").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![Erectors Pack
MRL Traction Full Lifts Spec]![chrLiftType]))
.ActiveDocument.Bookmarks("Floors").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![Erectors Pack
MRL Traction Full Lifts Spec]![lngFloors]))
.ActiveDocument.Bookmarks("SiteName").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrJobname]))
.ActiveDocument.Bookmarks("SiteAddress1").Select
.Selection.Text = (CStr(Forms![Erectors Pack Form]![chrJobaddress]))
.ActiveDocument.Bookmarks("SiteAddress2").Select
.Selection.Text = (CStr(Forms![Erectors Pack
Form]![chrJobaddress1]))
.ActiveDocument.Bookmarks("SiteAddress3").Select
.Selection.Text = (CStr(Forms![Erectors Pack
Form]![chrJobaddress2]))

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 Function

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 Function

End Function
 
G

Guest

Send the formatted value to Word, e.g.

..Selection.Text = "LC" & Format(Forms![Erectors Pack
Form]![SomeControl],"00-0000-00")
 

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