By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,164 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,164 IT Pros & Developers. It's quick & easy.


P: 173

i have a form that requires validation. i am using the following code:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me.number) Then
MsgBox "number is required", vbOKOnly
Cancel = True
End If

i have repeated the above code for other fields.........

The problem i have is, if i click 'x' and before it allows me to exit, it brings up the validations, one by one (so annoying).

Is there any way THAT it can show all the validations at once??? in one message????

Nov 21 '06 #1
Share this Question
Share on Google+
2 Replies

P: 143
You could use a function. Then call this function from your text boxes.

Public Function ValidateNumeric(strText As String) As Boolean
ValidateNumeric = CBool(strText = "" Or strText = "-" Or strText = "-." Or strText = "." Or IsNumeric(strText))
MsgBox "Not Numeric"
End Function
Nov 21 '06 #2

Expert 5K+
P: 8,434
Is there any way THAT it can show all the validations at once??? in one message????
What about a routine you can call (much like that proposed by Tanis) which does something like...
Expand|Select|Wrap|Line Numbers
  1. Private Function FieldsAreOK(ByVal ShowMsgBox As Boolean) As Boolean
  2.   ClearMessage
  3.   If <Validation1> Then
  4.     AddToMessage "Field1 must be numeric"
  5.   End If
  6.   If <Validation2> Then
  7.     AddToMessage "Field2 must be numeric"
  8.   End If
  9.   If <Validation3> Then
  10.     AddToMessage "Field3 doesn’t look right for some reason"
  11.   End If
  12.   ... and so on...
  13.   If Msg <> ""
  14.     If ShowMsgBox then
  15.       MessageBox "The following errors should be addressed:" & VbNewLine & Msg
  16.     End If
  17.   Else
  18.     FieldsAreOK = True
  19.   End If  
And you'd define a form variable Msg As String, and a couple of subs as follows
Expand|Select|Wrap|Line Numbers
  1. Private Sub ClearMessage
  2.   Msg = ""
  3.   ' (You could just do this in your code instead of calling the Sub)
  4. End Sub
  6. Private Sub AddToMessage (ByVal What As String)
  7.   Msg = Msg & iif(Msg = "", "", VbNewLine) & What
  8. End Sub
You could also get it to highlight the fields in some way (colour, border, font style, etc etc) but then you have the issue of changing them back.
Nov 21 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.