Group:  Microsoft Word ยป microsoft.public.word.docmanagement
Thread: Delete if form field is not defined

Geek News

Delete if form field is not defined
Skrewdriver1979 12/12/2008 7:30:03 PM
I currently have a text form field that is conditional where when you type
"OH" or "OHIO" and that state information appears elsewhere in the form. If
the field is left blank, it clears the state information. Is there a way that
if someone places something other then a state or something that is not
defined in the 'Case ""', that will delete the state infromation?
Right now if someone types "OH" the state information changes to Ohio, etc.,
but if you type "asdf" then the state information stays with OH.
Re: Delete if form field is not defined
"Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> 12/13/2008 9:55:00 AM
If the field in question is Text1 then the following macro run on exit from
Text1 will allow the user to enter the state letters or the full state name
in upper or lower case and the state name will be entered into the field in
upper case. Any other entry will clear the entered text. If you want to trap
that empty field then add the second macro to run on entry to the following
field - here Text2

Sub OnExitText1()
Dim oT1 As String

With ActiveDocument.FormFields("Text1")
oT1 = .Result
Select Case UCase(oT1)

Case "AL"
.Result = "ALABAMA"
Case "ALABAMA"
.Result = "ALABAMA"
Case "ALABAMA"
.Result = "ALABAMA"
Case "AK"
.Result = "ALASKA"
Case "ALASKA"
.Result = "ALASKA"
Case "AS"
.Result = "AMERICAN SAMOA"
Case "AMERICAN SAMOA"
.Result = "AMERICAN SAMOA"
Case "AZ"
.Result = "ARIZONA"
Case "ARIZONA"
.Result = "ARIZONA"
Case "AR"
.Result = "ARKANSAS"
Case "ARKANSAS"
.Result = "ARKANSAS"
Case "CA"
.Result = "CALIFORNIA"
Case "CALIFORNIA"
.Result = "CALIFORNIA"
Case "CO"
.Result = "COLORADO"
Case "COLORADO"
.Result = "COLORADO"
Case "CT"
.Result = "CONNECTICUT"
Case "CONNECTICUT"
.Result = "CONNECTICUT"
Case "DE"
.Result = "DELAWARE"
Case "DELAWARE"
.Result = "DELAWARE"
Case "DC"
.Result = "DISTRICT OF COLUMBIA"
Case "DISTRICT OF COLUMBIA"
.Result = "DISTRICT OF COLUMBIA"
Case "FM"
.Result = "FEDERATED STATES OF MICRONESIA"
Case "FEDERATED STATES OF MICRONESIA"
.Result = "FEDERATED STATES OF MICRONESIA"
Case "FL"
.Result = "FLORIDA"
Case "FLORIDA"
.Result = "FLORIDA"
Case "GA"
.Result = "GEORGIA"
Case "GEORGIA"
.Result = "GEORGIA"
Case "GU"
.Result = "GUAM"
Case "GUAM"
.Result = "GUAM"
Case "HI"
.Result = "HAWAII"
Case "HAWAII"
.Result = "HAWAII"
Case "ID"
.Result = "IDAHO"
Case "IDAHO"
.Result = "IDAHO"
Case "IL"
.Result = "ILLINOIS"
Case "ILLINOIS"
.Result = "ILLINOIS"
Case "IN"
.Result = "INDIANA"
Case "INDIANA"
.Result = "INDIANA"
Case "IA"
.Result = "IOWA"
Case "IOWA"
.Result = "IOWA"
Case "KS"
.Result = "KANSAS"
Case "KANSAS"
.Result = "KANSAS"
Case "KY"
.Result = "KENTUCKY"
Case "KENTUCKY"
.Result = "KENTUCKY"
Case "LA"
.Result = "LOUISIANA"
Case "LOUISIANA"
.Result = "LOUISIANA"
Case "ME"
.Result = "MAINE"
Case "MAINE"
.Result = "MAINE"
Case "MH"
.Result = "MARSHALL ISLANDS"
Case "MARSHALL ISLANDS"
.Result = "MARSHALL ISLANDS"
Case "MD"
.Result = "MARYLAND"
Case "MARYLAND"
.Result = "MARYLAND"
Case "MA"
.Result = "MASSACHUSETTS"
Case "MASSACHUSETTS"
.Result = "MASSACHUSETTS"
Case "MI"
.Result = "MICHIGAN"
Case "MICHIGAN"
.Result = "MICHIGAN"
Case "MN"
.Result = "MINNESOTA"
Case "MINNESOTA"
.Result = "MINNESOTA"
Case "MS"
.Result = "MISSISSIPPI"
Case "MISSISSIPPI"
.Result = "MISSISSIPPI"
Case "MO"
.Result = "MISSOURI"
Case "MISSOURI"
.Result = "MISSOURI"
Case "MT"
.Result = "MONTANA"
Case "MONTANA"
.Result = "MONTANA"
Case "NE"
.Result = "NEBRASKA"
Case "NEBRASKA"
.Result = "NEBRASKA"
Case "NV"
.Result = "NEVADA"
Case "NEVADA"
.Result = "NEVADA"
Case "NH"
.Result = "NEW HAMPSHIRE"
Case "NEW HAMPSHIRE"
.Result = "NEW HAMPSHIRE"
Case "NJ"
.Result = "NEW JERSEY"
Case "NEW JERSEY"
.Result = "NEW JERSEY"
Case "NM"
.Result = "NEW MEXICO"
Case "NEW MEXICO"
.Result = "NEW MEXICO"
Case "NY"
.Result = "NEW YORK"
Case "NEW YORK"
.Result = "NEW YORK"
Case "NC"
.Result = "NORTH CAROLINA"
Case "NORTH CAROLINA"
.Result = "NORTH CAROLINA"
Case "ND"
.Result = "NORTH DAKOTA"
Case "NORTH DAKOTA"
.Result = "NORTH DAKOTA"
Case "MP"
.Result = "NORTHERN MARIANA ISLANDS"
Case "NORTHERN MARIANA ISLANDS"
.Result = "NORTHERN MARIANA ISLANDS"
Case "OH"
.Result = "OHIO"
Case "OHIO"
.Result = "OHIO"
Case "OK"
.Result = "OKLAHOMA"
Case "OKLAHOMA"
.Result = "OKLAHOMA"
Case "OR"
.Result = "OREGON"
Case "OREGON"
.Result = "OREGON"
Case "PW"
.Result = "PALAU"
Case "PALAU"
.Result = "PALAU"
Case "PA"
.Result = "PENNSYLVANIA"
Case "PENNSYLVANIA"
.Result = "PENNSYLVANIA"
Case "PR"
.Result = "PUERTO RICO"
Case "PUERTO RICO"
.Result = "PUERTO RICO"
Case "RI"
.Result = "RHODE ISLAND"
Case "RHODE ISLAND"
.Result = "RHODE ISLAND"
Case "SC"
.Result = "SOUTH CAROLINA"
Case "SOUTH CAROLINA"
.Result = "SOUTH CAROLINA"
Case "SD"
.Result = "SOUTH DAKOTA"
Case "SOUTH DAKOTA"
.Result = "SOUTH DAKOTA"
Case "TN"
.Result = "TENNESSEE"
Case "TENNESSEE"
.Result = "TENNESSEE"
Case "TX"
.Result = "TEXAS"
Case "TEXAS"
.Result = "TEXAS"
Case "UT"
.Result = "UTAH"
Case "UTAH"
.Result = "UTAH"
Case "VT"
.Result = "VERMONT"
Case "VERMONT"
.Result = "VERMONT"
Case "VI"
.Result = "VIRGIN ISLANDS"
Case "VIRGIN ISLANDS"
.Result = "VIRGIN ISLANDS"
Case "VA"
.Result = "VIRGINIA"
Case "VIRGINIA"
.Result = "VIRGINIA"
Case "WA"
.Result = "WASHINGTON"
Case "WASHINGTON"
.Result = "WASHINGTON"
Case "WV"
.Result = "WEST VIRGINIA"
Case "WEST VIRGINIA"
.Result = "WEST VIRGINIA"
Case "WI"
.Result = "WISCONSIN"
Case "WISCONSIN"
.Result = "WISCONSIN"
Case "WY"
.Result = "WYOMING"
Case "WYOMING"
.Result = "WYOMING"
Case Else
.Result = ""

End Select
End With
End Sub

Sub OnEntryText2()
Dim oT2 As String
With ActiveDocument.FormFields("Text1")
oT2 = .Result
If Len(oT2) < 2 Then
MsgBox "Enter the correct full state name or abbreviation letters",
_
vbCritical, "Incorrect Entry"
.Select
End If
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Skrewdriver1979 wrote:
[Quoted Text]
> I currently have a text form field that is conditional where when you
> type "OH" or "OHIO" and that state information appears elsewhere in
> the form. If the field is left blank, it clears the state
> information. Is there a way that if someone places something other
> then a state or something that is not defined in the 'Case ""', that
> will delete the state infromation?
> Right now if someone types "OH" the state information changes to
> Ohio, etc., but if you type "asdf" then the state information stays
> with OH.


Re: Delete if form field is not defined
Skrewdriver1979 12/15/2008 10:35:01 PM
Helpful, but not quite what i am looking for. See below for what i am
running, the string is longer then 256 characters hence the
ActiveDocument.Bookmarks. What i am looking for is if someone fills in
Ontario, Asia, or something other then defined in the macro in the form field
case it will cause an error and/or delete all the
Range.Fields(1).Results.Text.

Case "AK", "ALASKA"
ActiveDocument.Unprotect Password:="password"

ActiveDocument.Bookmarks("LLStatesVehicle").Range.Fields(1).Result.Text = ""

ActiveDocument.Bookmarks("LLStatesCustomer").Range.Fields(1).Result.Text = ""

ActiveDocument.Bookmarks("LLStatesFiling").Range.Fields(1).Result.Text = ""
ActiveDocument.Bookmarks("DaysOut").Range.Fields(1).Result.Text = ""
ActiveDocument.Bookmarks("Repairs").Range.Fields(1).Result.Text = ""
ActiveDocument.Bookmarks("PeriodMonths").Range.Fields(1).Result.Text
= ""
ActiveDocument.Bookmarks("PeriodMiles").Range.Fields(1).Result.Text
= ""
ActiveDocument.Bookmarks("ContExist").Range.Fields(1).Result.Text = ""
ActiveDocument.Bookmarks("Safety").Range.Fields(1).Result.Text = ""
ActiveDocument.Bookmarks("SafetyTime").Range.Fields(1).Result.Text =
""
ActiveDocument.Bookmarks("SafetyMiles").Range.Fields(1).Result.Text
= ""
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="password"
Re: Delete if form field is not defined
"Graham Mayor" <gmayor[ at ]REMOVETHISmvps.org> 12/16/2008 10:27:28 AM
If you are using Case statements to define what is allowed, use a Case Else
at the end to define what happens when something other is entered.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Skrewdriver1979 wrote:
[Quoted Text]
> Helpful, but not quite what i am looking for. See below for what i am
> running, the string is longer then 256 characters hence the
> ActiveDocument.Bookmarks. What i am looking for is if someone fills in
> Ontario, Asia, or something other then defined in the macro in the
> form field case it will cause an error and/or delete all the
> Range.Fields(1).Results.Text.
>
> Case "AK", "ALASKA"
> ActiveDocument.Unprotect Password:="password"
>
> ActiveDocument.Bookmarks("LLStatesVehicle").Range.Fields(1).Result.Text
> = ""
>
> ActiveDocument.Bookmarks("LLStatesCustomer").Range.Fields(1).Result.Text
> = ""
>
> ActiveDocument.Bookmarks("LLStatesFiling").Range.Fields(1).Result.Text
> = ""
>
>
> ActiveDocument.Bookmarks("DaysOut").Range.Fields(1).Result.Text = ""
>
> ActiveDocument.Bookmarks("Repairs").Range.Fields(1).Result.Text = ""
>
>
>
> ActiveDocument.Bookmarks("PeriodMonths").Range.Fields(1).Result.Text
> = ""
> ActiveDocument.Bookmarks("PeriodMiles").Range.Fields(1).Result.Text =
> ""
> ActiveDocument.Bookmarks("ContExist").Range.Fields(1).Result.Text =
> "" ActiveDocument.Bookmarks("Safety").Range.Fields(1).Result.Text =
> "" ActiveDocument.Bookmarks("SafetyTime").Range.Fields(1).Result.Text
> = ""
> ActiveDocument.Bookmarks("SafetyMiles").Range.Fields(1).Result.Text =
> "" ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
> Password:="password"


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net