Form Field Text and Case Options

J

Joshua

I'm trying to work my way through this and would appreciate any help I
can receive :)

I will give you examples to hopefully show you what I want. I'm trying
to prevent users from typing ALL caps.

If a user types the following text "THE LAZY BROWN FOX JUMPED SOME SILLY
FENCE" they get different results based on settings in box.

What I would like to see is "The lazy brown fox jumped some silly fence"

with Uppercase - "THE LAZY BROWN FOX JUMPED SOME SILLY FENCE"
with Lowercase - "the lazy brown fox jumped some silly fence"
with First capital - "THE LAZY BROWN FOX JUMPED SOME SILLY FENCE"
with Title Case - "The Lazy Brown Fox Jumped Some Silly Fence"

I found some code using google:

lPosOld = 1
lPos = 1
Set ffld = ActiveDocument.FormFields("Name")
szFieldContent = ffld.Result
Do
lPos = InStr(lPos, szFieldContent, ". ") + 1
If lPos > 1 Then
szNewContent = szNewContent & _
Mid(szFieldContent, lPosOld, lPos) & _
UCase(Mid(szFieldContent, lPos+1, 1)
lPos = lPos + 1
lPosOld = lPos
End if
Loop While lPos > 1
ffld.Result = szNewContent

But it frowns at the section:

szNewContent = szNewContent & _
Mid(szFieldContent, lPosOld, lPos) & _
UCase(Mid(szFieldContent, lPos+1, 1)

I think I understand the jist of the code.. ipos sets current location
in Field, iposold sets previous location, it goes through each character
until it finds a period and then goes one past the space of the period
and changes the case.

I'm not familiar enough with VBA to know if I need to define
sznewcontent beforehand or how to even do that properly :(

If anyone could assist with this I would greatly appreciate it.

Thanks,

Joshua
 
D

Doug Robbins - Word MVP

Just use

ActiveDocument.FormFields("Name").Range.Case = wdTitleWord

or

ActiveDocument.FormFields("text1").Range.Case = wdTitleSentence


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Joshua

Doug said:
Just use

ActiveDocument.FormFields("Name").Range.Case = wdTitleWord

or

ActiveDocument.FormFields("text1").Range.Case = wdTitleSentence

How would I apply this to the exit macro? Which is what I assume I want
to do.

The code you provide is straightforward, I just don't know how to be non
descript and apply it to the current formfield using an exit macro.
 
J

Joshua

Doug said:
Just use

ActiveDocument.FormFields("Name").Range.Case = wdTitleWord

or

ActiveDocument.FormFields("text1").Range.Case = wdTitleSentence
First off thanks for the help!

How would I apply this to the exit macro? Which is what I assume I want
to do.

The code you provide is straightforward, I just don't know how to be non
descript and apply it to the current formfield using an exit macro.
 
J

Jay Freedman

Joshua said:
First off thanks for the help!

How would I apply this to the exit macro? Which is what I assume I
want to do.

The code you provide is straightforward, I just don't know how to be
non descript and apply it to the current formfield using an exit
macro.

See http://word.mvps.org/FAQs/TblsFldsFms/GetCurFmFldName.htm for the
general technique.

If your macro is never assigned as the exit macro for any kind of field
other than a text form field, it simplifies to this:

Dim FieldName As String
FieldName = Selection.Bookmarks(Selection.Bookmarks.Count).Name
ActiveDocument.FormFields(FieldName).Range.Case = wdTitleSentence

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

Joshua

Thanks alot for your help Jay.

I was able to figure out why I was having such a rough time.

Apparently the bookmarks code for text box's wont work unless you
specify a name for the Text Box.

May seem stupid but thats why my code I was writing wasn't working and
also why your didn't work originally.

Your code worked perfectly once I gave the textbox a name :)

Thanks again!

Joshua
 

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