sending the 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
 
D

Douglas J. Steele

Formatting a record doesn't change its underlying value.

You could try

..Selection.Text = (Format(Forms![Erectors Pack
Form]![chrJobNoID]),"""LC""@@-@@@@-@@")

or you could try changing your input mask to "LC"00-0000-00;0, so that it
stores the formatted input.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



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
 
G

Guest

Thanks for taking the time to explain this, storing the format worked great

Douglas J. Steele said:
Formatting a record doesn't change its underlying value.

You could try

..Selection.Text = (Format(Forms![Erectors Pack
Form]![chrJobNoID]),"""LC""@@-@@@@-@@")

or you could try changing your input mask to "LC"00-0000-00;0, so that it
stores the formatted input.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



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
 

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