473,785 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Validation of Field

101 New Member
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 1573
missinglinq
3,532 Recognized Expert Specialist
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 New Member
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,578 Recognized Expert Moderator MVP
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 Recognized Expert Specialist
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,578 Recognized Expert Moderator MVP
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
2782
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 invalid data or required fields not filled in) and the frontend will generate an initial value of items WITHOUT errors (so the user doesn't have to reenter valid info). This is the problem. The frontend generates the initial value attribute...
5
9724
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 ApplicationResources.properties file, the propertise file is in the right location, it is referenced from the struts-config.xml, but still no messages. For example, submitting a form that violates the required field validator, just causes it to do...
5
2422
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 description blank and I do get the error messages. But the code still continues to run the addfolder method from my class. Is there something wrong with this?
2
3014
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 local system that validations work.plz tell that whats the problem in that. Here is my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html...
0
9483
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10096
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.