Solved Validation Rules on Form Close/Click on Previous record (1 Viewer)

ahmad_rmh

Member
Local time
Today, 18:34
Joined
Jun 26, 2022
Messages
243
I am applying validation rules on form close/go to previous record on main form and subform. The requirements are as under;

1. If the user just enters the information on the main form and wants to save record or wants to exit then show a message,
"You cannot record a blank transaction".
2. Undo/delete the information if he wants to leave.

3. On the other hand, if the user directly enters the items detail on the sub form and leaves the main form blank and wants to save the record or exit then show a message,
"Warehouse information cannot be left blank"
4. Undo/delete the information if he wants to leave.

Suggestions are required please.
 

mike60smart

Registered User.
Local time
Today, 15:34
Joined
Aug 6, 2017
Messages
1,899
Hi
This statement is all wrong:-

"
3. On the other hand, if the user directly enters the items detail on the sub form and leaves the main form blank and wants to save the record or exit then show a message,
"Warehouse information cannot be left blank"
4. Undo/delete the information if he wants to leave."

The purpose of a Main Form / Subform is to ensure that you have details in the Parent before you are allowed to
enter details for a Child record.
 

ahmad_rmh

Member
Local time
Today, 18:34
Joined
Jun 26, 2022
Messages
243
Hi
This statement is all wrong:-

"
3. On the other hand, if the user directly enters the items detail on the sub form and leaves the main form blank and wants to save the record or exit then show a message,
"Warehouse information cannot be left blank"
4. Undo/delete the information if he wants to leave."

The purpose of a Main Form / Subform is to ensure that you have details in the Parent before you are allowed to
enter details for a Child record.

Who has told you this is all wrong,

It's up to you at which place you want to make limitionations or validations,

For the end user easiness, Many modern software are working like this.

So, I will move on this way.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:34
Joined
Jul 9, 2003
Messages
16,245
Who has told you this is all wrong,

You want to wind your neck in a bit mate, you're starting to piss people off. Mike is trying to tell you that you can't save a record in the subform without a record in the main form, it just won't work. So try and listen to people and stop being a dick!
 
Last edited:

ahmad_rmh

Member
Local time
Today, 18:34
Joined
Jun 26, 2022
Messages
243
The same thing I have written that if anyone of the conditions will not met then it will pop up message.

But mike said, this statement is all wrong.

I want codes for the said conditions.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:34
Joined
Jul 9, 2003
Messages
16,245
I am applying validation rules on form close/go to previous record on main form and subform. The requirements are as under;

1. If the user just enters the information on the main form and wants to save record or wants to exit then show a message,
"You cannot record a blank transaction".
2. Undo/delete the information if he wants to leave.

3. On the other hand, if the user directly enters the items detail on the sub form and leaves the main form blank and wants to save the record or exit then show a message,
"Warehouse information cannot be left blank"
4. Undo/delete the information if he wants to leave.
Suggestions are required please.

A better approach would be to stop the user gaining access to the subform until they have completed the main form.
 

ahmad_rmh

Member
Local time
Today, 18:34
Joined
Jun 26, 2022
Messages
243
Thanks, it's simple and easy to implement but as you know I am a learner if I want to implement like that way then what is the solution.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:34
Joined
Jul 9, 2003
Messages
16,245
See here:-


And here:-

I prefer to lock the subform/subreport control, see here:-

Post in thread 'How do I lock a subform?' https://www.access-programmers.co.uk/forums/threads/how-do-i-lock-a-subform.200841/post-1012226
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:34
Joined
Feb 19, 2002
Messages
42,988
The simplest solution to preventing data entry in a subform is to use the subform's BeforeInsert event. This event runs ONLY for new records and it runs immediately after the user types the first character. In this event, you examine the PK of the main form. If it is Null, then you cancel the BeforeInsert event and give the user a message that he cannot enter data at this time.

Tony and I are making videos and this is referenced in our very first one.


You should be able to just click on play without creating an account.

Please let us know what you think. Thanks.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:34
Joined
Jul 9, 2003
Messages
16,245
Thanks, it's simple and easy to implement but as you know I am a learner if I want to implement like that way then what is the solution.

@ahmad_rmh
At time index 25 minutes in @Pat Hartman's video, there is an explanation of what you need to do, along with the code. Just copy the code presented in the video and hey presto, you should have a working validation routine...
 

ahmad_rmh

Member
Local time
Today, 18:34
Joined
Jun 26, 2022
Messages
243
Actually I am busy in management tasks in office today so I will let you know tomorrow,

Thanks
 

jdraw

Super Moderator
Staff member
Local time
Today, 11:34
Joined
Jan 23, 2006
Messages
15,364
Very helpful to see the Order of Events. The dialog between you two is also helpful.

Tony, I tried adding a comment to the video at the ScreenCastOmatic site, but was told
"oops an error has occurred- something went wrong - we are working on it". And it did offer a button to Go Back-but it did not go back???
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:34
Joined
Jul 9, 2003
Messages
16,245
Tony, I tried adding a comment to the video at the ScreenCastOmatic site

Thanks Jack, I'll let Screen o'matic know... They are pretty hot on getting things fixed!!!
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:34
Joined
Jul 9, 2003
Messages
16,245
Thanks Jack, I'll let Screen o'matic know...

Hi @jdraw ,
I went to the site to create a support ticket but I note that a comment appears in the list. From the way it reads, my guess is it was your comment... Can you see it it now?
 

GPGeorge

Grover Park George
Local time
Today, 08:34
Joined
Nov 25, 2004
Messages
1,776
The simplest solution to preventing data entry in a subform is to use the subform's BeforeInsert event. This event runs ONLY for new records and it runs immediately after the user types the first character. In this event, you examine the PK of the main form. If it is Null, then you cancel the BeforeInsert event and give the user a message that he cannot enter data at this time.

Tony and I are making videos and this is referenced in our very first one.


You should be able to just click on play without creating an account.

Please let us know what you think. Thanks.
I think that's the clearest explanation of the situation I've ever seen or heard. (y)
 

jdraw

Super Moderator
Staff member
Local time
Today, 11:34
Joined
Jan 23, 2006
Messages
15,364
Hi @jdraw ,
I went to the site to create a support ticket but I note that a comment appears in the list. From the way it reads, my guess is it was your comment... Can you see it it now?
Tony,
Yes that's my comment. Unsure what may have happened.

Just saw George's note, and I agree --very clear and focused info/explanation.
I like the idea of showing the events as they occur. I use it quite often - I think a forum or newsgroup (back in the day) encouraged people to show each event in order and review same. Event style programming is different than we were used to with Cobol. PL/1, Fortran....(y)
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:34
Joined
Jul 9, 2003
Messages
16,245
Very helpful to see the Order of Events. The dialog between you two is also helpful.

Hi Jack,
Further to this AWF comment, but really, more in answer to the comment you made on the screencast o'matic hosting site.

Yes there were some surprises in how the events are ordered.

Pat is working on the sample database (as per the one shown in the video), adding some features to make it easy to implement. I think her intention is to release a free copy to go along with the video. (it's not really my video, it's mostly Pat!) I'm trying to persuade Pat to release a free copy along with a "paid for" copy. In other words, two levels following the freemium model, basic dB provided free of charge and a dB with more advanced features, which must be paid for.

I haven't told her this yet!
 
Last edited:

jdraw

Super Moderator
Staff member
Local time
Today, 11:34
Joined
Jan 23, 2006
Messages
15,364
Tony,
I have a feeling she'll pick up on that little secret if she's following the forum.;)
Has she ever created Youtube content? Good voice, knowledgeable and experienced.

It would be nice if the Northwind 2 had some similar basic, but critical, info.
 

Users who are viewing this thread

Top Bottom