Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for Non numeric values of Form fields

Status
Not open for further replies.

barnard90

IS-IT--Management
Mar 6, 2005
73
US

Hi

I am having a certain form field in MS word document . It's name is " ffld ". It is to display amount and should accept numbers only. If text is entered , it should give a message that only numbers are entered and the focus of the cursor should be set back to the field " ffld ".

I have written the code below, but the set focus is giving a problem
Could some one please correct my code



If Not IsNumeric(ffld.Result) Then
MsgBox "This Field Accepts Numeric Values only"
ffld.Select
With ffld
.Enabled = True
.Select
End With
Exit Sub
End if


Thanks
 
If you are using the code as the OnExit macro for the formfield, essentially, it can't be done.

The OnExit fires when the focus exits the formfield - so it is NOT the Selection.

You can run the validation, display the message, remove the .Result, even reselect the formfield...but at the end of the OnExit the next formfield WILL get focus.

You need to run an OnEnter macro from the next field, and go back.

The frustrating thing about this is that you can write code that will do what you want, validate, message, remove incorrect entries, and reselect the formfield. If you step through it in the VBE it works perfectly. However, it will NOT work - the exact same procedure - from an OnExit macro. Simply because any OnExit macro from a formfield ALWAYS passes focus to the next formfield when it finishes running the procedure.

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top