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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output text bold & upper case?

Status
Not open for further replies.

air1jcw

Technical User
Jan 23, 2003
30
US
Below is code that works just fine. It outputs text from a form into a MSWord template. I would like to have the output type the text in uppercase & bold.

Any help??

Private Sub MergeButton_Click()

On Error GoTo MergeButton_Err

Dim objWord As Word.Application

Set objWord = CreateObject("Word.Application")

With objWord
.Visible = True

.Documents.Open ("D:\Documents and Settings\air1jcw\Desktop\Access VB Fun Practice\Ch1114.dot")
.ActiveDocument.ShowSpellingErrors = False

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("WWReviewGTWYs").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!ATTN))
.ActiveDocument.Bookmarks("IID").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!IID1))
.ActiveDocument.Bookmarks("Fleettype").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!FleetType))
.ActiveDocument.Bookmarks("Nomenclature").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!Nomenclature))
.ActiveDocument.Bookmarks("PN").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!PN))
.ActiveDocument.Bookmarks("GTWY1").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!GTWY1))
.ActiveDocument.Bookmarks("Hashave").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!hashave))
.ActiveDocument.Bookmarks("Deallocationreason").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!DeAllocationReason))
.ActiveDocument.Bookmarks("GTWY2").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!GTWY2))
.ActiveDocument.Bookmarks("GTWY3").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!GTWY3))
.ActiveDocument.Bookmarks("TotAlloc").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!TotalAllocations))
.ActiveDocument.Bookmarks("BOstatement").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!BO))
.ActiveDocument.Bookmarks("Summary").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!Summary))
.ActiveDocument.Bookmarks("IID2").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!IID1))
.ActiveDocument.Bookmarks("Totalcost").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!TotalCost))
.ActiveDocument.Bookmarks("email").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!emailcontact))
.ActiveDocument.Bookmarks("Atlas").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!ATLAS))
.ActiveDocument.Bookmarks("Phone").Select
.Selection.Text = (CStr(Forms!WWRDataEntry!PHONE))


End With

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


End Sub
 
Bold:
ActiveDocument.Content.Font.Bold = False/False
Selection.Font.Bold =true/false

Upper Case: Ucase$ example

.Selection.Text = Ucase$((CStr(Forms!WWRDataEntry!GTWY1)))


 
For the all upper case, you can use the UCase function like:

.Selection.Text = UCase(CStr(Forms!WWRDataEntry!ATTN))

For the bold, try using the the Font object on the selection like:

.Selection.Font.Bold = True

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
When the going gets tough, the tough gets going.
 
Quick suggestion - you can streamline your code quite a bit by giving your bookmarks the same name as the text boxes in your form.

Private Sub MergeButton_Click()
Dim objWord As Word.Application
Dim bkmk As Word.Bookmark


On Error GoTo MergeButton_Err

Set objWord = CreateObject("Word.Application")

With objWord
.Visible = True

.Documents.Open ("D:\Documents and Settings\air1jcw\Desktop\Access VB Fun Practice\Ch1114.dot")
.ActiveDocument.ShowSpellingErrors = False

'Move to each bookmark and insert text from the form.
For Each bkmk In .ActiveDocument.Bookmarks
.ActiveDocument.Bookmarks(bkmk.Name).Select
.Selection.Text = UCase(CStr(Forms!WWRDataEntry.Controls(bkmk.Name)))
.Selection.Font.Bold = True
Next bkmk
End With

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
End Sub
 
Good question.

At the risk of telling you something obvious. Using:

.Documents.Open ("filename.dot")

means that you are working directly with the template and risk making undesired changes if the save button is clicked in Word.

Whereas, using:

.Documents.Add Template:=("filename.dot")

means you are adding text to a new document and your users cannot stuff up a carefully prepared template.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top