Select format of Table FormField dependent upon data entered

F

Fred

Is it possible, using vb, to change the format of a Text form field in
a Table, dependent upon the data that has been entered ? I have the
situation where a cell, indicating the status of a kick-off meeting,
is to show any of the following values,
TbD To be Decided whether required or not
N/A Not Applicable/required to hold a meeting
100% Meeting held
dd-mmm-yyyy scheduled date for the meeting

I have it set at present to Regular Text, Unlimited. What I would like
to be able to do is switch to Date (dd-mmm-yyyy) or Number (%) or
leave it as text, based upon the data entered.

Regards
Fred
 
J

Jean-Guy Marcil

Fred was telling us:
Fred nous racontait que :
Is it possible, using vb, to change the format of a Text form field in
a Table, dependent upon the data that has been entered ? I have the
situation where a cell, indicating the status of a kick-off meeting,
is to show any of the following values,
TbD To be Decided whether required or not
N/A Not Applicable/required to hold a meeting
100% Meeting held
dd-mmm-yyyy scheduled date for the meeting

I have it set at present to Regular Text, Unlimited. What I would like
to be able to do is switch to Date (dd-mmm-yyyy) or Number (%) or
leave it as text, based upon the data entered.

This can be a bit hairy and totally dependent on user good behaviour...

First, since the format may change from entering to leaving the field, you
may get a problem so that the user is not allow to leave the field if, for
example, it was set to date but it is changed to "TbD"; in this case, "TbD"
is not a valid date format and Word will not let the user leave the field.
This is why I included a macro for Entry to reset the field format to
regular text upon entry:

OnEntry macro:
'_______________________________________
Sub ResetFormat()

Dim ffTarget As FormField
Dim strFFResult As String

Set ffTarget = Selection.Paragraphs(1).Range.FormFields(1)

With ffTarget
strFFResult = .Result
.Result = ""
With .TextInput
.EditType Type:=wdRegularText, Format:=""
End With
.Result = strFFResult
End With

End Sub
'_______________________________________


OnExit macro:
'_______________________________________
Sub ChangeFormat()

Dim ffTarget As FormField
Dim strFFResult As String

Set ffTarget = Selection.Paragraphs(1).Range.FormFields(1)

With ffTarget
strFFResult = .Result
.Result = ""
If IsNumeric(strFFResult) Then
With .TextInput
.EditType Type:=wdNumberText, Format:="0%"
End With
strFFResult = CStr(CLng(strFFResult) / 100)
Else
If IsNumeric(Replace(strFFResult, "-", "")) Then
With .TextInput
.EditType Type:=wdDateText, Format:="dd-MMM-yyyy"
End With
Else
With .TextInput
.EditType Type:=wdRegularText, Format:=""
End With
End If
End If
.Result = strFFResult
End With

End Sub
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
F

Fred

Merci beaucoup Jean-Guy

One thing I omitted to mention is that I am using Word97 and VB has
thrown a fit with the statement

If IsNumeric(Replace(strFFResult, "-", "")) Then

Is this a feature of Word2000 or an in-house routine you have ?

Regards
Fred
 

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