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

GPGeorge

Grover Park George
Local time
Today, 13:59
Joined
Nov 25, 2004
Messages
1,867
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.
Stay tuned. It might turn out that way. ;)

Unfortunately, projects like this tend to take a long time to complete.
 

jdraw

Super Moderator
Staff member
Local time
Today, 16:59
Joined
Jan 23, 2006
Messages
15,379
Tony,

See. George spotted a secret within my message.🕵️‍♂️
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 21:59
Joined
Jul 9, 2003
Messages
16,282
Has she ever created Youtube content? Good voice, knowledgeable and experienced.

Exactly! She's a natural!
 

GPGeorge

Grover Park George
Local time
Today, 13:59
Joined
Nov 25, 2004
Messages
1,867
Tony,

See. George spotted a secret within my message.🕵️‍♂️
"It would be nice if the Northwind 2 had some similar basic, but critical, info"

I assumed you meant documentation and video support. We won't try to teach Access. We'll try to explain how "Northwind" illustrates features. But that's a big task, too.
 

ahmad_rmh

Member
Local time
Today, 23:59
Joined
Jun 26, 2022
Messages
243
Thanks Pat and Tony for the sharing of this knowledgeable and informative video.

You both have deeply cleared that what the access is doing at the back end on behalf of us if we are doing something wrong.

And cleared so many points which i was wandering around.

Thanks a lot.
 

jdraw

Super Moderator
Staff member
Local time
Today, 16:59
Joined
Jan 23, 2006
Messages
15,379
I understand that Pat was a regular presenter at local MS Access Groups...
Yes. I recall a few years back that I was participant/listener on one of her evening CTUserGroups meetings.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 21:59
Joined
Jul 9, 2003
Messages
16,282
(it's not really my video, it's mostly Pat!)

The video represents an interesting collaboration between the USA and UK.

Pat hosted the meeting on gotomeeting, on which she has an account.

I recorded it with screencast-o-matic, and shared it on screencast-o-matic hosting, which I haven't used much before. I usually use YouTube.

>>>Edit<<<
Also we are over 3000 miles apart, and working together. IT'S amazing!
 
Last edited:

ahmad_rmh

Member
Local time
Today, 23:59
Joined
Jun 26, 2022
Messages
243
I give a salute to @CJ_London and @Pat Hartman to drive me into a new direction of database and form making and pushed me to make a single form for all of my inventory project.

I was a lit bit nervous at that time and at the end I have got success to finalise in that way. Still some points are remaining which would be posted later on.

Thanks a lot all of those who have given response time to time.
 
Last edited by a moderator:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:59
Joined
Feb 19, 2002
Messages
43,274
Thanks to all for the positive feed back. I like the interview format. It gives Tony an opportunity to ask questions he thinks the viewer might have. The form showing the events was an after thought but once I got it working I realized how very important it is as a learning tool. Tony and I had a few chuckles while we were making the video as we discovered events running that we didn't expect to run. One made the cut in the video.

The next video will show when and when not to use the control's BeforeUpdate event and hopefully also why you would never need to use events other than the two BeforeUpdate events for validation and if you do, hopefully the event log will clarify how bad data will slip through the cracks and get saved. Then I'll move on to other events. I'm open to suggestions so if you have a favorite, I'll consider it. Otherwise the third will be the BeforeInsert event and the Current event will probably be the fourth.

I came to Access as an experienced developer but I was using procedural logic which is quite different from event driven logic. I think form events are one of the most difficult things for newcomers to get their heads around. Even experienced Access developers have trouble figuring out which one to use.

I'm thinking about how best to enable users to import parts of my database so they can use the forms to show events in their own applications. The curmudgeon's way is to add the logging call to each event of your own form but that becomes a PITA. It is important that ALL events get logged so you can always see which ones run when. Since I've done this logging in one place, I will add a way to turn it off so you can actually leave it in your app but not write the log records unless you want to.
 

paisenhi8

New member
Local time
Tomorrow, 02:29
Joined
Aug 10, 2022
Messages
1
The same thing I have written that if anyone of the conditions will not met then it will pop up message.
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 16:59
Joined
Apr 27, 2015
Messages
6,341
Very helpful to see the Order of Events.
Absolutely. I did something similar a few years back but it was very crude - A MsgBox on each event so I could figure out what the blazes was going on. Their demo is MUCH more practical and informative.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:59
Joined
Feb 19, 2002
Messages
43,274
@paisenhi8 Welcome aboard:) I think we may have a language problem with your post. Try to write it in your own language and then use Google Translate to convert it to English. As long as we know you are using a translator, we can usually figure out what you mean when the translator produces something strange. Our membership is world wide and you might even find someone who understands your native language.

Also, unless your post is regarding the thread you posted in, it is far better to start a new thread for your own question rather than tack it onto an existing thread. Try again and we'll do our best to help you.
 

ahmad_rmh

Member
Local time
Today, 23:59
Joined
Jun 26, 2022
Messages
243
I have applied validation rule on before update event but I am getting compile error kindly check and suggest please. I have added the code and screenshot.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Forms!frmTransactionsMain!lblReceipt.Visible = True Then
        If CheckForEmpty = False Then
            MsgBox "Please fill in the coloured fields"
        Else
            MsgBox "Do Action"
        End If
    End If

End Sub

Function CheckForEmpty() As Boolean
   
    CheckForEmpty = True
    ClearControlFormatting
   
    Dim Ctrl As Control
   
    For Each Ctrl In Me.Controls
        If Ctrl.Tag = "Fill" Then
            If IsNull(Ctrl) Or Len(Ctrl) = 0 Then
                Ctrl.BackColor = RGB(153, 204, 255)
                CheckForEmpty = False
            End If
        End If
    Next
End Function

Sub ClearControlFormatting()
    Dim Ctrl As Control
   
    For Each Ctrl In Me.Controls
        If Ctrl.Tag = "Fill" Then
            Ctrl.backcolor = vbWhite
        End If
    Next
End Sub

Private Sub Form_Current()
    ClearControlFormatting
End Sub

It is showing compile error on "=" sign on CheckForEmpty in before update event.

Kindly suggest
 

Attachments

  • Capture.GIF
    Capture.GIF
    32.9 KB · Views: 71
Last edited:

NauticalGent

Ignore List Poster Boy
Local time
Today, 16:59
Joined
Apr 27, 2015
Messages
6,341
I have applied validation rule on before update event but I am getting compile error kindly check and suggest please. I have added the code and screenshot.
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Forms!frmTransactionsMain!lblReceipt.Visible = True Then
        If CheckForEmpty = False Then
            MsgBox "Please fill in the coloured fields"
        Else
            MsgBox "Do Action"
        End If
    End If

End Sub

Function CheckForEmpty() As Boolean()
   
    CheckForEmpty = True
    ClearControlFormatting
   
    Dim Ctrl As Control
   
    For Each Ctrl In Me.Controls
        If Ctrl.Tag = "Fill" Then
            If IsNull(Ctrl) Or Len(Ctrl) = 0 Then
                Ctrl.BackColor = RGB(153, 204, 255)
                CheckForEmpty = False
            End If
        End If
    Next
End Function

Sub ClearControlFormatting()
    Dim Ctrl As Control
   
    For Each Ctrl In Me.Controls
        If Ctrl.Tag = "Fill" Then
            Ctrl.baccolor = vbWhite
        End If
    Next
End Sub

Private Sub Form_Current()
    ClearControlFormatting
End Sub

It is showing compile error on "=" sign on CheckForEmpty in before update event.

Kindly suggest
Good morning. @GinaWhipp has the best Form Validation sub I have ever seen. Place her code in your BeforeUpdate event and your life will be much easier!
 

jdraw

Super Moderator
Staff member
Local time
Today, 16:59
Joined
Jan 23, 2006
Messages
15,379
I would start by removing the brackets after Boolean() in your CheckForEmpty() function.
 

ahmad_rmh

Member
Local time
Today, 23:59
Joined
Jun 26, 2022
Messages
243
I would start by removing the brackets after Boolean() in your CheckForEmpty() function.
Thanks @jdraw, i have removed () now no error but the form is not showing any response on blank fields. Kindly suggest.

@NauticalGent , this is beyond my scope, may be this would work, thanks
 
Last edited:

NauticalGent

Ignore List Poster Boy
Local time
Today, 16:59
Joined
Apr 27, 2015
Messages
6,341
@NauticalGent , this is beyond my scope, may be this would work, thanks
Really nothing to it. You would place the code in a standard module (outside of any of your forms), then in each of your forms' BeforeUpdate event you would call it with
Code:
If fValidateData Then
     Cancel = True
     Exit Sub
End If
 

ahmad_rmh

Member
Local time
Today, 23:59
Joined
Jun 26, 2022
Messages
243
I will try
Really nothing to it. You would place the code in a standard module (outside of any of your forms), then in each of your forms' BeforeUpdate event you would call it with
Code:
If fValidateData Then
     Cancel = True
     Exit Sub
End If

I have tried this, this works but as you get notification of blank fields it freezes the form and records, and even after filling again the required fields it does not unfreezes the form fields.
 

Users who are viewing this thread

Top Bottom