Button on Subforms - showing related records (1 Viewer)

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:54
Joined
Feb 19, 2002
Messages
43,453
The original question seems to be why the wizard doesn't open in the subform when you edit it via the main form. None of us know why but I explained how to get the wizard to run. In #14, I explained that the wizard opens when you edit a main form but not a subform. But, if you open the subform directly, the wizard works. Apparently Matthew still hasn't tried that yet. He's too busy criticizing me.
 

MatthewB

Member
Local time
Today, 10:54
Joined
Mar 30, 2022
Messages
85
@MatthewB - we are now on post#19 for a question that should only have required a couple of responses. We are all volunteers here and your reluctance to provide any meaningful information is frustrating. Criticising those trying to help will not earn you any brownie points.

I've taken a look at your db - finally found what I believe to be the right form (stratas_F_C) and taken a look at the the button which has an embedded macro, not vba as we have been talking about. Adding a new button opens up the wizard. Wizards do not work on existing buttons.

I don't use macros as they are notoriously difficult to debug when things don't work as expected, but I do notice you are trying to open the other form using the strata name, not the ID.

What I don't see is where your problem is per post #1 'continuous form as a subform'
Thanks for your reply.Yes, it is unfortunately drawn out. I am challenged for time. I tried to provide meaningful information by striping out my DB and posting it. When I go to the Stratas_F_C (Strata Form Continuous) and put a button within a record I am able to open the Stratas_F document. So I can access the details of a strata through a list of stratas.
Within the strata_F there is a tab called Contracts (there are recurring issues from year to year to track). Within Contracts is a Contracts_F_C, however this time when I put the button within the record it does not open the Contracts_F.
So I read to not put buttons within an embedded subform, but to edit the subform directly.
I am not adept with VBA coding and use the Wizard and alike at this point in my learning.
I will try Pat Hartman's solution. Again I work at a job and I am trying to develop a db for myself in my spare time. I am challenged for time. Regards.
 
Last edited:

MatthewB

Member
Local time
Today, 10:54
Joined
Mar 30, 2022
Messages
85
I am back again. Trying to understand the commentary. For everyones info, I do not know enough VBA so I use the Wizard at this point in my learning
Since I started this thread I have created a Query that puts the Service and Supplier organized a2z.

Generally I am trying to show records related to the current StrataPlanNr (LMS2430 ect) . If there are 30 suppliers it would be better to just open the related Contract_T subform to see more. Is this possible?
How do I reference the StrataPlanNr to show only the records related to the current StrataPlanNr.
Updated db attached
Thanks
 

Attachments

  • EmptyDatabase.accdb
    2.8 MB · Views: 99

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:54
Joined
Feb 19, 2002
Messages
43,453
All of your relationships to trataPlan_T are incorrect. Relationships are ALWAYS Primary key which in this case would be kp_StrataPlanID, to foreign key which should be the same name whenever possible. Instead you are going data field (StrataPlanNr) to data field. You are also using table level lookups suck as ContractorLookup in Project_T. All this does is to obfuscate the actual data. The ID is stored in Project_T, NOT the company name so when you open Project_T, that is what you should see. Seeing the CompanyName just confuses the issue because you never know whether you need a number or a string to use this field.

That said, you are getting away with the first problem because you declared a unique index on StrataPlanNr. The best fix to this problem is to remove the autonumber since you are not actually using it and then define StrataPlanNr as the PK. That way, you won't ever run into the bug that occurs when a table holds an autonumber which is NOT being used as the primary key. Under mysterious conditions, the autonumber looses its seed and starts generating duplicates.

Removing the table level lookups is slightly more painful but as you get deeper into this project and start running into the problems they cause once you start writing more sophisticated queries and writing code, you will understand even though you don't understand now why they are a problem.

When you give us something to look at, it is most helpful if you actually give us the path to see what you are talking about Choose button x, then double click on field z, ..... Making us click on everything until we recognize some word from your description is just a waste of our time.

If there are 30 suppliers it would be better to just open the related Contract_T subform to see more. Is this possible?
It is not clear what this means. If you only want to see the subform, just open the subform. Don't open the main form. Subforms are just forms. They can be opened directly if that is what you want. You will have to use the Where argument in order to filter it properly but that's all it takes. If you want the option of opening either the main form or the subform, then add two buttons.

If you are talking about seeing the Contracts tab when the Stratas form opens, just change the order of the tabs. If you don't want to change the order of the tabs permanently but if you open this main form from the list form, only then do you want to see the Contracts first, you can do that by using the OpenArgs to pass in the name of the tab page you want to have the focus when the main form opens. Let us know and we'll provide the code.

Going back to the original question. This is what the main form looks like in design view. If you add a button to the Contracts subform in this view, the wizard will NOT activate. Close this main form and go back to the Navigation Pain (sic) and open Contracts_T subform itself in design view. Now when you add a button to the form, the wizard will activate. See the next picture for how that looks.
zzzsubform.JPG

zzzsubform2.JPG
 
Last edited:

MatthewB

Member
Local time
Today, 10:54
Joined
Mar 30, 2022
Messages
85
Thanks for your insights. I learned about relational databases using Filemaker. For some reason I cannot get the hang of how relationships work in Access. It is probably just terminology but I am not comfortable with what I am doing with Access. I will take your advice and reconfigure my db to the norm this weekend. Regards
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:54
Joined
Feb 19, 2002
Messages
43,453
Relationships are relationships. The relationships in Access are the same as they would be in SQL Server, Oracle, DB2, or any other RDBMS. I don't know if Filemaker is a relational database. dBase was not relational although there are some similarities.

You might want to find some articles on database normalization. I would avoid the ones published by universities. They get all wound up in relational algebra and relational calculus. You want something that explains the concepts in plain English. It doesn't mater what RDBMS, if any, the article uses as an example. The basic concepts of relational database I learned in the 70's are the same that are taught today. You might find articles by Codd or that refer to him which are old but still relevant today.

Database normalization description - Office | Microsoft Docs
Important Papers: Codd and the Relational Model (twobithistory.org)
 

PaquettePaul

Member
Local time
Today, 13:54
Joined
Mar 28, 2022
Messages
107
My prior response seems to have dropped into the ether. Oh well.

I had a similar problem with a continuous form where I wanted to click on a sub form record to cause a form to be opened. I thought of check boxes and buttons but they did not work. The simplest solution for me was to switch the sub form’s Record Selector property to Yes. With that, a button appears in front of each record in the continuous form

i created a VBA process for the OnClick event that saved the selected record’s primary key. At that point, you could open your form

In my case, I had multiple options including opening another form. I put the required options as buttons in the sub form’s footer. That way the user clicks on the record selector button for the desired record (where the record key is saved in a global variable), and then clicks on the option button in the footer, where the VBA code could open a form or do any other desired action.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 13:54
Joined
Feb 19, 2002
Messages
43,453
Except that double-clicking in some field on the subform solves the problem without needing to put a button on some other form. Plus, you have 100% certainty that you are selecting the record you want.

The RecordSelector is always on by default. If it was off, you turned it off. It doesn't need to be visible for the double-click to work.
 

Users who are viewing this thread

Top Bottom