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 
Multiple Closing Scenarios
Lisa Snider 
       
14 months ago
I have two forms, ProductF and ProductCompareF.  
ProductF defines products. On that form, there is a Close button (CLOSE_BTN).  Normally when CLOSE_BTN is pressed, it closes ProductF and opens MenuProductF.  Also on that form, there is a field named ProductCompare_TOG which, when toggled on, flags the specific product for use on multiple forms and reports, including ProductCompareF.
ProductCompareF is a continuous form, whose Record Source is ProductCompareQ,  where all products for which ProductCompare_TOG have been toggled ‘ON’ on ProductF.  On ProductCompareF, there is a button (ViewDetail_BTN) that opens ProductF (in edit view) to the specific record. This works fine, just as expected.  
And now, the question, is there a way to change the way CLOSE_BTN on ProductF works when the record has been accessed from ProductCompareF?  Rather than its usual method of closing ProductF and opening MenuProductF, I’d like it to just close ProductF and return focus to ProductCompareF (which is still open).

Is this even possible?
Lisa Snider OP  @Reply  
       
14 months ago
Addition:  Or do I need to create a clone of ProductF (READ ONLY) for use with ProductCompareF?  (Just a thought.)
Adam Schwanz  @Reply  
           
14 months ago
Just make an invisible checkbox on the form, set the default value to false. When you open the form from ProductCompareF, set the checkbox to true. Then you can do different things depending on if its true or false with if/then.

Something like this
Docmd.Openform "YourForm"
Forms!YourForm!InvisibleCheckbox=True
Kevin Robertson  @Reply  
          
14 months ago
I thought you would have suggested TempVars Adam
Sami Shamma  @Reply  
             
14 months ago
lol
Adam Schwanz  @Reply  
           
14 months ago
Kevin I failed :( lol.

Tempvars has been tossed to the side for debouncing now lol.

But yea Lisa, TempVars is acceptable as well :).
Jeffrey Kraft  @Reply  
      
14 months ago
I love tempvars.... they are saving my life right now on a project I'm changing.
Lisa Snider OP  @Reply  
       
14 months ago
Thanks for the responses fellas.  But I got to thinking about Richard saying you could store multiple tags and came up with this:  

Private Sub CLOSE_BTN_Click()
    On Error GoTo HandleError

    If InStr(1, Me.Tag, "COMPARE", vbTextCompare) > 0 Then
        ' Opened from ProductCompareF
        DoCmd.Close acForm, Me.Name

        ' Check if ProductCompareF is still open
        If CurrentProject.AllForms("ProductCompareF").IsLoaded Then
            ' Bring ProductCompareF to the front
            DoCmd.SelectObject acForm, "ProductCompareF", True
        Else
            ' ProductCompareF was closed, so open MenuProductF instead
            DoCmd.OpenForm "MenuProductF"
        End If
    Else
        ' Normal close behavior
        DoCmd.Close acForm, Me.Name
        DoCmd.OpenForm "MenuProductF"
    End If

    Exit Sub

HandleError:
    ' In case of unexpected error, open MenuProductF to ensure user has a landing spot
    DoCmd.OpenForm "MenuProductF"
End Sub
Lisa Snider OP  @Reply  
       
14 months ago
It took more than a few tries to get the code right, but it works beautifully, and I'll be tucking this one into the tool belt for future uses.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

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: 6/21/2026 9:31:27 PM. PLT: 0s