473,386 Members | 2,042 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,386 software developers and data experts.

Problem with Validation of Field

101 100+
Hi,
My project is in MS Access.
In that one form of data entry I am using this code for validation of field.
Expand|Select|Wrap|Line Numbers
  1. Private Sub CustomerCode_Combo_LostFocus()
  2.     If Me.CustomerCode_Combo = "" Or IsNull(Me.CustomerCode_Combo) Then
  3.     strMsg = "You must select Customer Code from the ComboBox."
  4.     strTitle = "CustomerCode Required"
  5.     intStyle = vbOKOnly
  6.     MsgBox strMsg, intStyle, strTitle
  7.     Me.CustomerCode_Combo.Undo
  8.     Me.CustomerCode_Combo.SetFocus
  9.     End If
  10. End Sub
Its not working properly.
only First time whenever I lostfocus of this feild and go to next field to this field then it shows msg whatever I enter in validation.But even if I used that line
Me.CustomerCode_Combo.Undo
Me.CustomerCode_Combo.SetFocus

its not setfocus to that feild again and its useless.
And I can go further even validation is not correct.
I don't know what's the problem?
Jan 21 '08 #1
5 1532
missinglinq
3,532 Expert 2GB
Validation for a required field has to be in the Form's BeforeUpdate event; if the user doesn't go to the combobox at all, its LostFocus event will never fire! Also, if nothing is selected from the combobox, there's nothing to Undo. Instead use Cancel = True, which "undoes" the save , if you will. So try this

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  If Me.CustomerCode_Combo = "" Or IsNull(Me.CustomerCode_Combo) Then
  3.   strMsg = "You must select Customer Code from the ComboBox."
  4.   strTitle = "CustomerCode Required"
  5.   intStyle = vbOKOnly
  6.   MsgBox strMsg, intStyle, strTitle
  7.   Cancel = True
  8.   Me.CustomerCode_Combo.SetFocus
  9. End If
  10. End Sub 
  11.  
Please use code tags when posting code.

Linq ;0)>
Jan 21 '08 #2
billa856
101 100+
I am using this code for my whole form.
But its not working at all.Now its simply enter anything.No validation anymore.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3.  If Me.CustomerCode_Combo = "" Or IsNull(Me.CustomerCode_Combo) Then
  4.   strMsg = "You must select Customer Code from the ComboBox."
  5.   strTitle = "CustomerCode Required"
  6.   intStyle = vbOKOnly
  7.   MsgBox strMsg, intStyle, strTitle
  8.   Cancel = True
  9.   Me.CustomerCode_Combo.SetFocus
  10. End If
  11.  
  12. If Me.Date_Text = "" Or IsNull(Me.Date_Text) Then
  13.     strMsg = "You must Enter Order Date."
  14.     strTitle = "ODate Required"
  15.     intStyle = vbOKOnly
  16.     MsgBox strMsg, intStyle, strTitle
  17.     Cancel = True
  18.     Me.Date_Text.SetFocus
  19. End If
  20.  
  21. If Me.LONo_Text = "" Or IsNull(Me.LONo_Text) Then
  22.     strMsg = "You must Enter the LO No"
  23.     strTitle = "LONo Required"
  24.     intStyle = vbOKOnly
  25.     MsgBox strMsg, intStyle, strTitle
  26.     Cancel = True
  27.     Me.LONo_Text.SetFocus
  28. End If
  29.  
  30. If Me.PONo_Text = "" Or IsNull(Me.PONo_Text) Then
  31.     strMsg = "You must Enter the PO No"
  32.     strTitle = "PONo Required"
  33.     intStyle = vbOKOnly
  34.     MsgBox strMsg, intStyle, strTitle
  35.     Cancel = True
  36.     Me.PONo_Text.SetFocus
  37.  
  38. End If
  39.  
  40. If Me.ItemNo_Combo = "" Or IsNull(Me.ItemNo_Combo) Then
  41.     strMsg = "You must Select the Item No from the ComboBox"
  42.     strTitle = "ItemNo Required"
  43.     intStyle = vbOKOnly
  44.     MsgBox strMsg, intStyle, strTitle
  45.     Cancel = True
  46.     Me.ItemNo_Combo.SetFocus
  47. End If
  48.  
  49. If Me.Description_Text = "" Or IsNull(Me.Description_Text) Then
  50.     strMsg = "You must Select the Description from the ComboBox"
  51.     strTitle = "Description Required"
  52.     intStyle = vbOKOnly
  53.     MsgBox strMsg, intStyle, strTitle
  54.     Cancel = True
  55.     Me.Description_Text.SetFocus
  56. End If
  57.  
  58. If Me.BatchOrLotNo_Text = "" Or IsNull(Me.BatchOrLotNo_Text) Then
  59.     strMsg = "You must Enter the Batch Or Lot No"
  60.     strTitle = "BatchOrLotNo Required"
  61.     intStyle = vbOKOnly
  62.     MsgBox strMsg, intStyle, strTitle
  63.     Cancel = True
  64.     Me.BatchOrLotNo_Text.SetFocus
  65. End If
  66.  
  67. If Me.Cartons_Text = "" Or IsNull(Me.Cartons_Text) Then
  68.     strMsg = "You must Enter the Cartons"
  69.     strTitle = "Cartons Required"
  70.     intStyle = vbOKOnly
  71.     MsgBox strMsg, intStyle, strTitle
  72.     Cancel = True
  73.     Me.Cartons_Text.SetFocus
  74. End If
  75.  
  76. If Me.PcsOrCarton_Text = "" Or IsNull(Me.PcsOrCarton_Text) Then
  77.     strMsg = "You must Enter the Pcs Or Carton"
  78.     strTitle = "PcsOrCarton Required"
  79.     intStyle = vbOKOnly
  80.     MsgBox strMsg, intStyle, strTitle
  81.     Cancel = True
  82.     Me.PcsOrCarton_Text.SetFocus
  83. End If
  84.  
  85. End Sub
Jan 21 '08 #3
NeoPa
32,556 Expert Mod 16PB
I would consider using the control's BeforeUpdate event procedure myself. The Form one is good if it's a bound form, but there are circumstances where you'd prefer using one per control. Specifically, it will trigger the response when the field is left, rather than when the record is left.

Let us know how you get on with this idea.
Jan 22 '08 #4
missinglinq
3,532 Expert 2GB
Huh? The OP ia checking that given controls have data! If the user doesn't go to the control and enter a value, the control's BeforeUpdate event doesn't fire; how does this work to assure that it has a value? A control's BeforeUpdate event is usually used to make sure that the data entered is appropriate; you have to use the form's BeforeUpdate if you want to assure that a control is populated.

Linq ;0)>
Jan 22 '08 #5
NeoPa
32,556 Expert Mod 16PB
I'm sorry Linq, and I certainly mean no disrespect.
I don't have the confidence you have that the OP expressed his intentions at all clearly. Read one way you could be right. I interpreted his question a little differently, and I'm not sure he's dealing with a bound form at all. I thought I'd made that clear in my post though. It's not a contradiction of yours (as far as I can see and certainly not intended). I was just trying to cover areas that didn't quite match the question as asked, on the understanding that sometimes the questions aren't perfectly expressed.
Jan 22 '08 #6

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

Similar topics

3
by: TekWiz | last post by:
I've got a system that automatically generates a form. I have it set up so that the backend will return to the inital form page with an error object in sessions data (assuming the backend detected...
5
by: Alex M | last post by:
I'm trying to use the jakarta struts client side javascript validators and the validators are working, but they are not showing the popup messages. I have the message keys defined in the...
5
by: Do | last post by:
Hi, Has anybody run into problems with Page.IsValid? My errors show up when the fields aren't filled correctly, but my processing continues even if the page is invalid. I leave name and...
2
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.