higlight fileds with differetn color if the entry is null (1 Viewer)

sanrar

New member
Local time
Today, 04:12
Joined
Apr 19, 2019
Messages
2
hi

i have created a form to create a record.

i want the empty fields to be highlighted in different color and once the user enter s the data it color needs to go away.

I want to select the whole form and then do a one line code for all the present fileds as i have 25 fileds in form
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:12
Joined
Oct 29, 2018
Messages
21,447
Hi. Welcome to the forum! Have you seen this demo from Allen Browne?
 

sanrar

New member
Local time
Today, 04:12
Joined
Apr 19, 2019
Messages
2
Thanks for providing me a quick one.
I created a form with 20 fields, i want to add a new record from form to the table but i dont want the user to add the record till all the fields are entered is there a simple way of coding this.
 

June7

AWF VIP
Local time
Today, 03:12
Joined
Mar 9, 2014
Messages
5,463
Use Conditional Formatting to highlight empty fields.

Data validation is common topic. Options:

1. form BeforeUpdate event to validate data

2. disable X close as well as right click menu and ribbon and use a command button to close form and/or save data, have validation code in this procedure
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:12
Joined
Feb 19, 2002
Messages
43,196
The Form's BeforeUpdate event is the LAST event that fires before a record gets saved so that is the appropriate place to put most of your validation. You can change the table definition to set all fields as required and AllowZeroLengthStrings to No and remove any 0 default that Access automatically adds for numeric fields. The upside to that is you don't need any code. The downside is you get the default message which isn't going to be too helpful to the user.

Do NOT put validation code in a command button. That can be circumvented by just ignoring the message and closing the database. You can have the command button save the dirty record and that will cause the BeforeUpdate event to run but the BeforeUpdate event is where the code belongs since there is no way around that event. It ALWAYS runs no matter what caused the record to be saved.
 

June7

AWF VIP
Local time
Today, 03:12
Joined
Mar 9, 2014
Messages
5,463
That's why I said to disable all those other avenues to close form and db. It gets complicated hence it is option 2 but I did build a db that way.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:12
Joined
Feb 19, 2002
Messages
43,196
You can use the BeforeUpdate event which is the event intended for this purpose by the original Access development team OR you can set some properties and put code in a lot of events and hope you've handled everything. I suggest you go back to that old database, start to add a record and just close the app. What happens?
 

Users who are viewing this thread

Top Bottom