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

VB Code check please

67
Hi All

I am having a little problem with the following code. I can't seem to get it to go back to focus on the Contact field. Please Advise.

Private Sub Contact_LostFocus()
If IsNull(Contact) Then
MsgBox "This field must be filled in!"
Me.Contact.SetFocus
End If
End Sub


Regards

Wayne
Jan 15 '09 #1
4 1241
MikeTheBike
639 Expert 512MB
@Wayneyh
Hi

I think perhaps you should use the BeforeUpdate Event something like this.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Contact_BeforeUpdate(Cancel As Integer)
  2.     If IsNull(Contact) Then
  3.         MsgBox "This field must be filled in!"
  4.         Cancel = True
  5.     End If
  6. End Sub
This will prevent focus from leaving the control if it is null.

Hope that helps.

MTB
Jan 15 '09 #2
missinglinq
3,532 Expert 2GB
As to the
I can't seem to get it to go back to focus on the Contact field
this is one of those quirks of Access. The focus both has and hasn't actually left the field in question when the LostFocus event fires. The way to beat this, as Mike TheBike has suggested, is to use the BeforeUpdate event and use the line

Cancel = True

The problem with using the BeforeUpdate event of the textbox for this kind of validation is that the user can simply not enter the textbox at all, in which case the validation won't take place at all! You need to place the code in the form's BeforeUpdate. This will insure that the user has to fill in the data.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.      If IsNull(Me.Contact) Then
  3.          MsgBox "This field must be filled in!"
  4.          Cancel = True
  5.          Me.Contact.SetFocus
  6.      End If
  7.  End Sub
  8.  
This is true for data validation that is intended to insure that a given field is populated before saving the record . Validation that is intended to insure that data entered into a field complies with some criteria, such as an ID number containing only numeric characters or a description field only containing alpha characters, can be placed in either the BeforeUpdate event of the textbox or the form.

Linq ;0)>
Jan 15 '09 #3
Wayneyh
67
Ok, the code works fine. The problem i now have is that the contact field is the first field on the form. When the sales form loads and if i tab away from the contact field the code doesn't work. How do i activate the form so that the code works.

Regards

Wayne
Jan 15 '09 #4
Wayneyh
67
sorry guys my mistake. i put the code in the contact fields beforeupdate instead of the forms. works fine now. thanks
Jan 16 '09 #5

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

Similar topics

4
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers...
38
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser =...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
2
by: LordBlue | last post by:
Hi, please forgive me if i'm sending this post in the wrong place, and please don't tell me to post it in another group, because if i found a better one i'd have already done it. I'm writing a...
3
by: cisco | last post by:
Let's say i have something, that will eat up a lot of cpu cycles, that i want to run for the whole webpage( asp.net application and all subfolders underneath). What's the best way to accomplish...
1
by: =?Utf-8?B?Wmlub24=?= | last post by:
Hello I have an ASP.NET 2 intranet application written in C#. I use Active Directory authentication and parts of the application uses AJAX. From time to time (about once every 200-300 accesses...
7
by: robin1983 | last post by:
Hi, good morning everyone, i have a file called attendence.php The problem is that some part of code is executing properly and half of the code is not and i dont get any warning or error message. For...
29
by: Virtual_X | last post by:
As in IEEE754 double consist of sign bit 11 bits for exponent 52 bits for fraction i write this code to print double parts as it explained in ieee754 i want to know if the code contain any...
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: 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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.