473,399 Members | 4,254 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,399 software developers and data experts.

Access Help - How to ensure a field is enter in the form

17
Hello Again,

I need help and advise.

I create a form in my database and I would like certain field in my form have to be entered, meaning, if I goto that field, it will automatically check and if it is empty, it will pop up with an error message "You Must enter this field"

Can you please advise how to do?

Thank You
Raymond
Jul 31 '07 #1
8 2668
BradHodge
166 Expert 100+
There are a few ways that you can do this. If you just want it filled out before the form is closed, you can set the Field in the table to Required YES.

If you want it alert the user before going onto the next field on the form, you can use code similar to this...

Expand|Select|Wrap|Line Numbers
  1. Private Sub field1_AfterUpdate()
  2. If IsNull (Me.field1) Then
  3. MsgBox ("This field is required before proceeding.")
  4. Me.field1.SetFocus
  5. End If
  6. End Sub
Hope this helps,
Brad.
Jul 31 '07 #2
missinglinq
3,532 Expert 2GB
Brad, your first suggestion is the simplest, of course, but your code won't work. The AfterUpdate event doesn't occur until data has been entered, so if field1 is null, the code won't be run!

The same code can be run in the Form_BeforeUpdate sub, and will be run after data is entered in any field if field1 is empty.

You could place the code in the field1_LostFocus event to check for null and pop the message when the user exits the field, but the code will only run if the user actually enters field1 to begin with. If you only had the single field you wanted to make required, you could set focus to field1 in the Form_Current() sub and then it would work.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.   If IsNull(Me.field1) Then
  3.    MsgBox ("This field is required before proceeding.")
  4.    Cancel = True
  5.    Me.field1.SetFocus
  6.   End If
  7.  End Sub
  8.  
Expand|Select|Wrap|Line Numbers
  1.  Private Sub field1_LostFocus()
  2. If IsNull(Me.field1) Then
  3.   MsgBox ("This field is required before proceeding.")
  4.   Me.AnyOtherField.SetFocus 'has to go elsewhere before returning to field1
  5.   Me.field1.SetFocus
  6.  End If
  7. End Sub
Linq ;0)>
Aug 1 '07 #3
damonreid
114 Expert 100+
Why not just make them required fields when you set up the table? That way it will not allow you to move focus from that record without having all the information you want filled in?
Aug 1 '07 #4
BradHodge
166 Expert 100+
Ahh yes... the old didn't update, so of course it can't check for Null. Must have been sleeping at my desk :)

Brad.
Aug 1 '07 #5
missinglinq
3,532 Expert 2GB
That was Brad's first suggestion, Damon!

Originally Posted by Brad:
"There are a few ways that you can do this. If you just want it filled out before the form is closed, you can set the Field in the table to Required YES."

And the fact of the matter is, a lot of people don't like the standard Access messages that pop up when a validation rule is violated!

Linq ;0)>
Aug 1 '07 #6
damonreid
114 Expert 100+
Sorry not sure how I missed that... brain not working.

Another option is to have all the controls bar one disabled and when you Change one control set the next one .Enabled = True thus forcing the person to enter values for each field before moving on. Have the Close form button hidden as well until the last option is inputted.
Aug 1 '07 #7
wongray
17
Thank you All,

I still have some problem. Let me try to explain it better.

I have a form with the following field

- Project_Name
- Status

The Project_Name is a field that I can enter anything
The Status is base on a Combo List

When I enter the code into the BeforeUpdate under Event Procedure in the Project_name field. it works, but if I have to cancel it, it will continue to give me the error and I can't exit from the form

for the Status field, the code does not work, not sure why, does it because it is a combo list?

Please advise, your help is much appreciated.

Many Thanks
Aug 3 '07 #8
missinglinq
3,532 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. When I enter the code into the BeforeUpdate under Event Procedure in the Project_name field. it works, but if I have to cancel it, it will continue to give me the error and I can't exit from the form 
Not being able to exit from the form is the entire idea behind making a field required! If you could simply ignore the warning it wouldn' t do much good, would it? Are you now saying you want the user to be able to dump the new record if they want to?

Is Status a combobox or a textbox?

Linq
Aug 3 '07 #9

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

Similar topics

2
by: qsweetbee | last post by:
I have a form(fAddUsers) in my database. It is continue form for data entry. Some fields are required fields. Some are optional fields. There is 1 particular filed(TokenExpirationDate)on the form...
2
by: Iain Miller | last post by:
Struggling a bit here & would be grateful for any help. I have a table which has a list of people in it. Each person has a unique ID automatically allocated by Access but also belongs to one of 5...
3
by: Megan | last post by:
I am not that good at Access and don't know much about it, so I have a few questions for anyone who knows Access very well. First off, I should mention that the company I work for uses Access as a...
9
by: J | last post by:
I have 2 Date fields DuesLastPaid DateDuesDue I want to enter the date of payment in last paid, and have one year from now show in the dues field In the AfterUpdate property of the last paid...
5
by: pnjones | last post by:
I am getting the write conflicit when 2 users access the same record the first one to save is allowed but the second user gets the message Write conflicit with the save option greyed out. I have...
1
by: puiatti | last post by:
Hi Guys, Any help offered on the below 2 queries (mind the pun) is gratefully received. 1) I'm constucting a db of betting results data. Each bet as a whole is called a "position" and every...
3
by: nicky77 | last post by:
Hi there, newish to javascript so grateful for any help. I am creating a test generator and have an array of textfields ("answer") created by a simple piece of PHP code. As you can see, I have...
0
by: lrheeza | last post by:
Hello Everyone, I am new in MS Access and I was tasked to create a porject. I have done some initial things already but need help and guidance: - I have a text field in a form where users are...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
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...
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
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,...

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.