473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Validation

173 100+
Hi,

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
Me.number.SetFocus
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????

THANKS
Nov 21 '06 #1
2 1340
Tanis
143 100+
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
Killer42
8,435 Expert 8TB
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  
  20.  
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
  5.  
  6. Private Sub AddToMessage (ByVal What As String)
  7.   Msg = Msg & iif(Msg = "", "", VbNewLine) & What
  8. End Sub
  9.  
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

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

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
2
by: wumingshi | last post by:
Hi, When validating an XML instance, sometimes the schema is not enough to expression the validation rules. Additional validation rules may be expressed in an application-specific way. For...
4
by: Tim Meagher | last post by:
I am trying to use both validation controls and to add submit button attributes, but when I add the button attributes, the javascript fpr the validation controls is no longer created for the page. ...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
6
by: Stephen | last post by:
Hi, the validation controls dont work on Netscape or Mozilla and only on Internet Explorer why? How do i correct this problem? Thanks
7
by: Ryan Ternier | last post by:
We're running a site that has required field validation on the login page. It works fine on our development / test machines. However, when I upload this site to our live server i get this error. ...
5
by: Chris | last post by:
Based upon some prevoius postings on what to do for adding a 'add' row to a datagrid I utilize the footer to create the 'add' row. The only issue is that I have it sharing the 'UpDate_Command' and...
4
by: David Colliver | last post by:
Hi all, I am having a slight problem that hopefully, someone can help me fix. I have a form on a page. Many items on the form have validation controls attached. Also on this form are...
2
by: dustbort | last post by:
I recently had a problem where my required field validator stopped working. But, the page still posted back and tried to insert a record into the database without performing server-side validation....
6
by: Jon Paal | last post by:
validation doesn't fire what's missing ????? /////// ---- code -----/////////////////////////// Sub btnSubmit_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) 'Handles...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.