Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Turn Before Update Into a Public Function
Monica Jones 
       
22 hours ago
Hi all,

I have a form that I want users to be very careful about editing. I built the following to test out (yes that's Richard's AreYouSure function) (Side quest, how do y'all do the Detail with the down arrow for code?):

Private Sub AHPPH_ACT_FRQ_BeforeUpdate(Cancel As Integer)
    If Not IsNull(Screen.ActiveControl.Name) Then
        If AreYouSure() Then
            'User procedes
            Exit Sub
        Else
            'User stays put
            Cancel = True
      End If
    End If
End Sub

This works just fine. I realized I could move this to the GlobalMod and not copy/paste all over the place. I changed Exit Sub to Exit Function, and it no longer stops me from doing whatever. I figure this has to be because "Cancel = True" only works in a BeforeUpdate setting. How do I translate for a GlobalMod situation?

TIA,
Monica
Donald Blackwell  @Reply  
       
21 hours ago
Monica
I don't think it works to move the actual BeforeUpdate event into the global mod and have it work because the globalmod isn't listening for the events of the form, only if a sub or function that is there is called does it activate.

However, you can make a function in your global mod that does whatever you're trying to do and return a boolean to the beforeupdate event in a form which will then do what you want. For instance

Form:
Private Sub AHPPH_ACT_FRQ_BeforeUpdate(Cancel As Integer)

   If OKtoContinue() Then Exit Sub ' Value Entered, continue

   ' The nothing was entered
   Cancel = True

End Sub

GlobalMod:
Public Function OKtoContinue() as Boolean

   OKtoContinue= False

   If Not IsNull(Screen.ActiveControl.Name) Then
      If AreYouSure() Then OKtoContinue= True
   end if

End Function

Mike Wolf has a good article on this type of functioning called Guard Clauses
Add a Reply Upload an Image
Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/9/2026 7:12:57 AM. PLT: 0s