Okey here goes @NeoPa, I'll try to make a correct post :)
I am trying to create a project where I want to display staff members and view their profiles. A profile contains personal data like address etc, this I have not built yet tho. So far I am building the profiles section called "Kontrakt". Kontrakt means contract and a staff member can have one or many contracts.
I have the following tables:
1. Profile_tbl = contains names of staff members
2. Contract_tbl = contains contract information
3. Role_tbl = subtable to contract, contains names of what contract roles are availible.
4. Jobbarpa_tbl = subtable to contract, contains names of what places staff members can be hired on.
These are the forms I have:
1. SelectProfile_frm = User starts here, gets a listbox to double click the name of the staffmember he want to work on. When double clicking next form opens.
2. Profile_frm = this is the main profile form. Here the name of the staff members is displayed and then a tab control where I have two tabs so far. Tab "Kontrakt" should display the staffīs one or many contracts.
3. Contract_frm = display the contract in several textboxes, is a subform to profile_frm where contract_frm is placed under tab "Kontrakt".
Currently this works on my db:
User can open selectprofile_frm and double click a staff member and bring up the profile_frm. Here I see the names of the profile and I see the tab control. When selecting the tab Kontrakt I see a listbox where I see the contracts of the that specific staff member. The listbox is getting itīs data from contract_tbl and jobbarpa_tbl and role_tbl.
When I select a row in the listbox in profile_frm under Kontrakt tab, it populates textboxes in contract_frm (subform under the listbox).
The subform is with Masterfield as the listbox in profile_tbl and childfield as contract_ID. This is to get the function "when selecting a row in listbox, it display that IDīs data in textobxes in contract_frm).
Now I want to create a new record, a new contract in contract_tbl. To do this my idea is to have a button under the listbox either in profile_frm or in contract_frm. Click the button and all fields in contract_frm should become empty and the user can populate them with new data. When done a new contract record is created and a new row should be displayed in the listbox as a new record/contract.
When I am trying to do this I get errors that the profile_id is not being connected to the new contract record. This I belive is that because my subform is not having the normal child and master relationship, but changing that and I remove the function of having "select row and populate textboxes".
I have tried things like this.
in button on click event
- DoCmd.GoToRecord , , acNewRec
in contract_frm startup (on load event)
- If Not IsNull(Me.OpenArgs) Then
-
Me.contract_id = Me.OpenArgs
-
End If
but so far I always get stuck on that the new record can not be created since it does not get the correct IDīs right..... profile_id and contract_id
I have attatched a few screenshots that I hope can help understanding what I have done. for those that want, I have also made a short video that you can view here:
https://streamable.com/gv279
I see one thing I could do (dont know how tho).
1. Change the master/child relationship to what access suggest, profile_ID and Profile_ID_SK (primary key and secondary key in contract_tbl). It feels like this would solve the situation of creating a new post.
But if I do this, then the function that populate the textboxes in contract_frm when selecting a row in the listbox will be destroyed and I do not know how to do that in another way.
2. I could create a "add new record" form that is standalone and opens up in a new window... but that is so ugly and nothing I want
Just a heads up. I do want my listbox where to select the contracts. I do not want to change the listbox to a combobox.
And just to clarify: The current amount of columns in my tables are just the beginning. The listbox will display a preview of a contract.... the textboxes in contract_frm will display everything in the future. And I do know that I should hide the ID fields later on.
I hope this post is better than my first and someone are able to come with tips on a solution. Hopefully this post did not become too large and too messy :)




