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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set Validation Rule

Status
Not open for further replies.

Loui2005

Programmer
Jan 12, 2005
8
US
Hi guys!

I'm working on a form that has 2 text boxes 1 for numeric values and the 2nd for strings, but I need to create a Validation Rule to prevent users enter strings in a numeric field. I also want to display a message to users that they must use the Comment box for strings.

Any help on this will be greatly appreciated.
Thnaks so much for your time
 
Hi
This might work for you. First, set the format of the numeric textbox to General Number or other suitable numeric format. Next, paste the code below into the module for the form:
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
   Const FORMAT_VIOLATION = 2113
   If DataErr = FORMAT_VIOLATION Then
      MsgBox "Please use this box for numbers." _
      & vbCr & "The other box is for comments"
      Screen.ActiveControl.Undo
      Response = acDataErrContinue
   End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top