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 1573
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,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.
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,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.
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 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...
|
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...
|
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?
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |