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 
Swapping Subforms With SourceObject
Colin Philben 
     
2 months ago
I have a form that I want to use as a main interface and just switch out the sub form (SFormFrame) on the right.  I am using SourceObject to do that.  I can get that part to work but when I click on the button in the contracts list it wont filter the data for that specific contract on the detail form.  I get an error 2467 "The expression you entered refers to an object that is closed or doesn't exist".  I'm not an expert at this by any means but I can usually find my way with a bit of guidance.  

Here is the Button code I'm using.

Private Sub OpenContractDetailBtn_Click()

' Clear link
Me.Parent.SFormFrame.LinkMasterFields = ""
Me.Parent.SFormFrame.LinkChildFields = ""

' Change source object
Me.Parent.SFormFrame.SourceObject = "ContractF"

' Re-link
Me.Parent.SFormFrame.LinkChildFields = "ContractID"
Me.Parent.SFormFrame.LinkMasterFields = "ContractID"

' refresh
Me.Parent.SFormFrame.Form.Requery
Colin Philben OP  @Reply  
     
2 months ago

Colin Philben OP  @Reply  
     
2 months ago

Kevin Robertson  @Reply  
          
2 months ago
Colin Philben OP  @Reply  
     
2 months ago
Syntax can sometimes still be a mystery.  I'm not sure I understand where the ! should be vs. the dot. Can you explain further please
Donald Blackwell  @Reply  
       
2 months ago
One thing I kind of used to help remember when to use bang (! - exclamation point) instead of dot (. - period) was to kind of think of it as a "Eureka" moment, like OH!!!! OH!!! I have an idea how to make the form better, I'll add a text-box, or an image, whatever type of control. If it's not available if you create a new form by clicking the "Form Design" tab on the ribbon, then "Eureka!" adding this makes it better so always use the bang! operator for notation.

Whereas, properties exist as soon as the form does: Me.Caption, Me.Section(0) (aka Me.Detail or just Detail). You don't add them there just there, period.

Hope this helps more than confuses you. It's just a little mnemonic trick of sorts.
Bryan Coleman  @Reply  
     
2 months ago
Donald I like your way of rememebering
Bryan Coleman  @Reply  
     
2 months ago
Colin try this;
Me!Parent!SFormFrame.LinkChildFields = "ContractID"
Me!Parent!SFormFrame.LinkMasterFields = "ContractID"

or you can try just referencing the subform and control

SFormFrame.LinkChildFields = "ContractID"
SFormFrame.LinkMasterFields = "ContractID"
Monica Jones  @Reply  
       
2 months ago
Colin That looks sweet! And well beyond anything I would have done as a beginner!
Richard Rost  @Reply  
          
2 months ago
Timing is the other big piece here. When you change the SourceObject, that form isn't instantly ready. So if you immediately try to requery it or set links, you can get that 2467 error.

One quick trick you can try is just putting a tiny delay in there. Even a fraction of a second can give Access enough time to load the subform before you hit it with more code. Or better yet, move that logic into the subform's load event so you know it's ready.
Colin Philben OP  @Reply  
     
2 months ago
OK so to get around the timing issue so my data is passed I'm using tempvars :)  Once the contract ID is in tempvars its available to me anywhere until I set it to null.  I'm finding that tempvars are easier than trying to set parent/child relationships in the subform and filtering.  if I'm missing something doing it this way someone please let me know.
Richard Rost  @Reply  
          
41 days ago
If it works, it works. :)

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/12/2026 5:25:43 PM. PLT: 1s