473,411 Members | 1,895 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,411 software developers and data experts.

Lose focus at wrong time

Hello i have a data validation check upon lost focus for a vb textbox:
Expand|Select|Wrap|Line Numbers
  1. Private Sub fromText_LostFocus()
  2.  
  3. If IsNull(fromText.Text) = True Then
  4.     MsgBox StrMsg, vbExclamation   
  5.  
  6. End If
  7.  
  8. End Sub
  9.  
It will check if its null, if so it'll display an error message. But then it will lose focus, i want it to stay in that text box until the user enters something.
Aug 10 '07 #1
2 1427
pureenhanoi
175 100+
Hello i have a data validation check upon lost focus for a vb textbox:
Expand|Select|Wrap|Line Numbers
  1. Private Sub fromText_LostFocus()
  2.  
  3. If IsNull(fromText.Text) = True Then
  4.     MsgBox StrMsg, vbExclamation   
  5.  
  6. End If
  7.  
  8. End Sub
  9.  
It will check if its null, if so it'll display an error message. But then it will lose focus, i want it to stay in that text box until the user enters something.
Using Validate event instead of LostFocus.
If the value still null, set the Cancel = True to keep the focus
Aug 11 '07 #2
Killer42
8,435 Expert 8TB
Using Validate event instead of LostFocus.
If the value still null, set the Cancel = True to keep the focus
The Validate event has an added advantage.
Let's say you have a Cancel button or something. Generally, the user would not expect to have to enter a value in your field, just so they can exit by hitting Cancel. If you do the check in LostFocus, it will always complain about the null, even if the user is just trying to exit. But if you do it in Validate, you can skip it by setting the Cancel button's CausesValidation property to False. This simply means "don't bother triggering validation on the control we left, before entering this one".
Aug 11 '07 #3

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

Similar topics

2
by: Wai Man Chung | last post by:
Dear all, I have an asp page which upon opening a field will be set to be in focus so that user can type in data without the need to use the mouse to click on the field. However, after I add...
6
by: Mica Cooper | last post by:
Hi, I have a series of Select menus on a page. I am trying to allow the user to click on the Select title and have it popup a help window. This works fine with the following code except that all...
4
by: Stephen Poley | last post by:
The issue of the focus pseudo-class came up a few weeks ago, and I finally got around to trying it out (better late than never ...) The recommended order given for the pseudo-classes is link,...
4
by: Nitin | last post by:
Hi I have created function to check date and time. at the time of execution, if date is left empty the function returns the error message but then the focus goes to next field. Next filed is for...
2
by: chris | last post by:
Does anybody know how I can programmatically cause a textbox to lose focus and automatically jump to the next appropriate control. I have a custom textbox usercontrol whereby the requirement is...
4
by: OpticTygre | last post by:
If I create a checkbox dynamically: Dim NewCheckBox as New Checkbox Then, I display that checkbox on a form, how can I cause the checkbox to lose focus after a user clicks on it? TIA, ...
3
by: Patrick [MSFT] | last post by:
Let me preface this with the goal I'm trying to achieve is mimic a feature of another language (Dexterity used by Microsoft Dynamics) and so while a filling a drop down list is a workable solution...
3
by: boldt.lars | last post by:
This code works fine in Firefox and Opera, I can see that it put focus on the correct input in IE, but by the time the page has loaded completely it loses focus. The first time you enter the...
1
by: danyeungw | last post by:
I get the following from the link http://support.microsoft.com/kb/314206. I need to have both work - the page stays where it is and set focus to next control. Does anyone have solution? I have...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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
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...
0
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.