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
8 2668
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... - Private Sub field1_AfterUpdate()
-
If IsNull (Me.field1) Then
-
MsgBox ("This field is required before proceeding.")
-
Me.field1.SetFocus
-
End If
-
End Sub
Hope this helps,
Brad.
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. - Private Sub Form_BeforeUpdate(Cancel As Integer)
-
If IsNull(Me.field1) Then
-
MsgBox ("This field is required before proceeding.")
-
Cancel = True
-
Me.field1.SetFocus
-
End If
-
End Sub
-
- Private Sub field1_LostFocus()
-
If IsNull(Me.field1) Then
-
MsgBox ("This field is required before proceeding.")
-
Me.AnyOtherField.SetFocus 'has to go elsewhere before returning to field1
-
Me.field1.SetFocus
-
End If
-
End Sub
Linq ;0)>
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?
Ahh yes... the old didn't update, so of course it can't check for Null. Must have been sleeping at my desk :)
Brad.
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)>
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.
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
- 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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |