Input in Text Form Field to Generate Message Box

H

Harry F.

Hi,

I'm trying to generate message box if a particular string of text is
entered into a form field via a macro. The code I'm using is below, can
someone point out where I'm wrong?

Thanks,
Harry


Sub Leave_Field()
'
' Leave_Field Macro
' Macro created 4/24/2007 by Henry Fanelli
'
If ActiveDocument.Bookmarks("Swift1").Range.Text = "UBSWUS33" Or
ActiveDocument.Bookmarks("Swift1").Range.Text = "UBSWUS33XXX" Then
MsgBox "UBSWUS33 or UBSWUS33XXX should only be used for Wealth Management
International (WMI) accounts.", vbInformation, "Notice"
End If

End Sub
 
H

Helmut Weber

Hi Harry,

you're probably experimenting with formfields
and an on-exit macro, too.

Don't set the range of the formfields bookmark to text.
Set the formfields result to text.

Still, an on-exit macro will not trigger,
if you set the formfield's result programmatically.

If all is done programmtically,
the why not checking what is to be entered beforehand?

IMHO, you got to rethink the whole approach.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Harry F.

Hi Helmut,

I don't disagree with what you're saying - however, in some instances the
specified values are allowed - the mesasage box is only to remind the user
when. Also, I'm not trying to programatically set the form field result.
All I'm trying to do, is upon leaving the field, if the text input matches
either of the two values, to trigger the message box. Can this not be done?
 
H

Helmut Weber

Hi Harry,

the last I can think of is that Word gets
confused with too long strings.

I did my best.

Sub Test444444444()
ActiveDocument.FormFields(1).Result = "UBSWUS33"
Dim s1 As String
Dim s2 As String
Dim s3 As String
s1 = "UBSWUS33"
s2 = "UBSWUS33XXX"
s3 = ActiveDocument.FormFields(1).Result
If s3 = s1 Or s3 = s2 Then
MsgBox "UBSWUS33 or UBSWUS33XXX should only be used" & _
" for Wealth Management International (WMI) accounts.", vbInformation,
"Notice"
End If

End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Harry F.

Hi Helmut,

This looks like it should work, but how can I adapt it to handle
Bookmarks(Swift1) instead of FormField(1). I don't know the number of the
field, so I need to use bookmarks, and bookmark does not recognize the result
property.
 
B

Bear

Harry:

The formfield "name" is the bookmark name you assign to it. So if you
assigned (in the Text Form Field Options dialog box) the bookmark
"bkBearCode" to that text field, you could then access it using code like:

ActiveDocument.FormFields("bkBearCode").Result

Bear
 

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