• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

Validating text input into a numeic field

Hello,

Ive got a validation question for you.

On a form I want to validate that the value entered into a numeric field is actually a numeric.

Ive looked at the input validation section but that only seems to check on a save. I need to check as soon as someone leaves the field.

So...what Ive done is put some script into the Exiting event.

Ive got this...

Sub Exiting(Source As Field)
     
     Dim ws As  New NotesUIWorkspace
     Dim doc As NotesDocument
     
     Set uidoc = ws.CurrentDocument
     Set doc = uidoc.document
     
     If (Isnumeric(doc.annualdays(0)) = True) Then
          End
     Else
          Msgbox "You must enter a numeric value for this field",48,"Numeric Field Error"
     End If
End Sub


Now this works ok if you have a space or number in the field, but if you put a character in - 'a' for instance, then the script generates an error to the effect of "Variant does not contain a container"

Obviously this isnt an ideal error message for users...

Does anyone know how I can accomplish this?

Many thanks,

Mat
0
prenexus
Asked:
prenexus
  • 2
  • 2
1 Solution
 
HemanthaKumarCommented:
Hi Mat

The numeric fields always validate for numeric values, this is the default behavour, if it is a text value  then it will prompt u with the error message.

For that you must enable "automatically refresh field" in the form properties. If u do so then user is prompted with error msg saying that the value is incorrect.

Good luck
~Hemanth

0
 
AntonysinghCommented:
Hi prenexus,

Use a error handler in your code as shown in the following code, this will handle the error.

Dim ws As  New NotesUIWorkspace
      Dim doc As NotesDocument

       'Error handler
      On Error Goto errhand

      Set uidoc = ws.CurrentDocument
      Set doc = uidoc.document
      
      If (Isnumeric(doc.annualdays(0)) = True) Then
            End
            
      End If

'Error handle section.
      
errhand:
      Msgbox "You must enter a numeric value for this field",48,"Numeric Field Error"
      Call uidoc.gotofield("annualdays")
      Exit Sub


Hope this may help you.
Good luck,

-Antony.
0
 
prenexusAuthor Commented:
HemanthaKumar,

Thanks for the answer - and while it does provide a solution its not really what I was looking for.

Thanks,

Mat
0
 
prenexusAuthor Commented:
Antony,

Thanks for the comment! Thats exactly what I was looking for.
Whats more youve shown me a way to highlight the field that was causing the trouble as well.

Mat
0
 
HemanthaKumarCommented:
That's OK.

May be I don't know the whole picture, and Antony got it.

~Hemanth
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now