Hi,
My project is in MS Access.
In that one form of data entry I am using this code for validation of field. - Private Sub CustomerCode_Combo_LostFocus()
-
If Me.CustomerCode_Combo = "" Or IsNull(Me.CustomerCode_Combo) Then
-
strMsg = "You must select Customer Code from the ComboBox."
-
strTitle = "CustomerCode Required"
-
intStyle = vbOKOnly
-
MsgBox strMsg, intStyle, strTitle
-
Me.CustomerCode_Combo.Undo
-
Me.CustomerCode_Combo.SetFocus
-
End If
-
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?
5 1532
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 - Private Sub Form_BeforeUpdate(Cancel As Integer)
-
If Me.CustomerCode_Combo = "" Or IsNull(Me.CustomerCode_Combo) Then
-
strMsg = "You must select Customer Code from the ComboBox."
-
strTitle = "CustomerCode Required"
-
intStyle = vbOKOnly
-
MsgBox strMsg, intStyle, strTitle
-
Cancel = True
-
Me.CustomerCode_Combo.SetFocus
-
End If
-
End Sub
-
Please use code tags when posting code.
Linq ;0)>
I am using this code for my whole form.
But its not working at all.Now its simply enter anything.No validation anymore. - Private Sub Form_BeforeUpdate(Cancel As Integer)
-
-
If Me.CustomerCode_Combo = "" Or IsNull(Me.CustomerCode_Combo) Then
-
strMsg = "You must select Customer Code from the ComboBox."
-
strTitle = "CustomerCode Required"
-
intStyle = vbOKOnly
-
MsgBox strMsg, intStyle, strTitle
-
Cancel = True
-
Me.CustomerCode_Combo.SetFocus
-
End If
-
-
If Me.Date_Text = "" Or IsNull(Me.Date_Text) Then
-
strMsg = "You must Enter Order Date."
-
strTitle = "ODate Required"
-
intStyle = vbOKOnly
-
MsgBox strMsg, intStyle, strTitle
-
Cancel = True
-
Me.Date_Text.SetFocus
-
End If
-
-
If Me.LONo_Text = "" Or IsNull(Me.LONo_Text) Then
-
strMsg = "You must Enter the LO No"
-
strTitle = "LONo Required"
-
intStyle = vbOKOnly
-
MsgBox strMsg, intStyle, strTitle
-
Cancel = True
-
Me.LONo_Text.SetFocus
-
End If
-
-
If Me.PONo_Text = "" Or IsNull(Me.PONo_Text) Then
-
strMsg = "You must Enter the PO No"
-
strTitle = "PONo Required"
-
intStyle = vbOKOnly
-
MsgBox strMsg, intStyle, strTitle
-
Cancel = True
-
Me.PONo_Text.SetFocus
-
-
End If
-
-
If Me.ItemNo_Combo = "" Or IsNull(Me.ItemNo_Combo) Then
-
strMsg = "You must Select the Item No from the ComboBox"
-
strTitle = "ItemNo Required"
-
intStyle = vbOKOnly
-
MsgBox strMsg, intStyle, strTitle
-
Cancel = True
-
Me.ItemNo_Combo.SetFocus
-
End If
-
-
If Me.Description_Text = "" Or IsNull(Me.Description_Text) Then
-
strMsg = "You must Select the Description from the ComboBox"
-
strTitle = "Description Required"
-
intStyle = vbOKOnly
-
MsgBox strMsg, intStyle, strTitle
-
Cancel = True
-
Me.Description_Text.SetFocus
-
End If
-
-
If Me.BatchOrLotNo_Text = "" Or IsNull(Me.BatchOrLotNo_Text) Then
-
strMsg = "You must Enter the Batch Or Lot No"
-
strTitle = "BatchOrLotNo Required"
-
intStyle = vbOKOnly
-
MsgBox strMsg, intStyle, strTitle
-
Cancel = True
-
Me.BatchOrLotNo_Text.SetFocus
-
End If
-
-
If Me.Cartons_Text = "" Or IsNull(Me.Cartons_Text) Then
-
strMsg = "You must Enter the Cartons"
-
strTitle = "Cartons Required"
-
intStyle = vbOKOnly
-
MsgBox strMsg, intStyle, strTitle
-
Cancel = True
-
Me.Cartons_Text.SetFocus
-
End If
-
-
If Me.PcsOrCarton_Text = "" Or IsNull(Me.PcsOrCarton_Text) Then
-
strMsg = "You must Enter the Pcs Or Carton"
-
strTitle = "PcsOrCarton Required"
-
intStyle = vbOKOnly
-
MsgBox strMsg, intStyle, strTitle
-
Cancel = True
-
Me.PcsOrCarton_Text.SetFocus
-
End If
-
-
End Sub
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.
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)> 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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
| |