Log in

View Full Version : Word 2007 Bookmark formatting.



deustim
08-15-2011, 11:00 AM
I use access 2007 data to push to a word template. The merge function works fine but I cannot figure how to use .Case to format indivdual bookmarks. Here is an excerpt of my code:

Dim Word As New Word.Application
Set Word = CreateObject("Word.Application")
Dim MergeDoc As String
MergeDoc = Application.CurrentProject.Path
MergeDoc = MergeDoc + "\DIAKanswer.dotx"
Word.Documents.Add MergeDoc
Word.Visible = True
With Word.ActiveDocument.Bookmarks

.Item("txtSAUSAName").Range.Text = Nz(Me.txtSAUSAName)
.Item("txtSAUSAName3").Range.Text = Nz(Me.txtSAUSAName)
.Item("txtSAUSAName4").Range.Text = Nz(Me.txtSAUSAName)

I wish to format the txtSAUSAName3 bookmark to always output the data as uppercase, ideally using something like wdUpperCase.

Thank You.

Frosty
08-15-2011, 01:38 PM
replacing your "Nz" with "UCase" (unless that represents some custom function which is also doing other stuff, in which case, you'll need to put UCase in that separate function)

deustim
08-15-2011, 02:00 PM
As per MSDN: You can use the Nz function to return zero, a zero-length string (" "), or another specified value when a Variant is Null. For example, you can use this function to convert a Null value to another value and prevent it from propagating through an expression.

I was just using it for Null values, but I will try the UCase and I assume LCase. Thank You.

deustim
08-15-2011, 02:03 PM
Worked great is there a function that will do Sentence Case?

Frosty
08-15-2011, 02:43 PM
Not to my knowledge. I'm away from the computer, so I can't write up quick proof of concept, but you probably should keep the nZ and just put UCase outside it (so you don't have failures on null). It shouldn't be too touch to write a sentence case function using Left...something like

stemp=UCase(left(stemp,1)) & right(stemp, Len(stemp) - 1))

Initial caps might be a little trickier, but look at the Split function and splitting on " "

deustim
08-15-2011, 03:15 PM
I did that already with the UCase(Nz(Me.txtSAUSAName)) worked perfectly. As for a sentence case function I will have to think on it more as I am worried that for strings of undetermined length you would have to define each sentence.