Results 1 to 6 of 6
  1. #1
    Behedwin is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    61

    Question New record in subform - need help to find a solution.

    Hey

    I need some help to solve a problem with creating a new record.
    i have uploaded my project in both 2016 and 2003 version of access!
    Please view the zip file where both files are.

    to find the place i want help finding a solution to you go to:
    1. open form "selectprofile_frm"


    2. then doubleclick on a name in the listbox
    3. go to tab "Kontrakt"
    4. here you see a listbox and a button and some textboxes. when i click the button, i want to create a new record in table "contract_tbl".

    I have setup things like this
    Form selectprofile_frm is where i select what staff member i want to work on.
    then i double click and open the proifle in form "profile_frm".
    here i view data and update and add new. so far i have only come to create the "kontrakt" tab.
    Under the contract tab there is a listbox and a subform.
    Subform goes to "contract_frm" that display the contract information.
    listbox is just to select what contract to display.

    but now i want to add the feature of adding a new contract.
    i get it to work just fine when not using the subform... but i want to do it in the subform.
    how can this be done?

    let me know if i should post screenshots or anything else.

    hope someone can help.

    upload proj.zip

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Comments in-line:

    Form selectprofile_frm is where i select what staff member i want to work on.
    then i double click and open the proifle in form "profile_frm".
    OK, did that. I selected Anna.
    here i view data and update and add new. so far i have only come to create the "kontrakt" tab.
    Under the contract tab there is a listbox and a subform.
    Subform goes to "contract_frm" that display the contract information.
    The sub form is a bound form with bound controls.
    listbox is just to select what contract to display.
    When a record is selected in the list box, the sub form moves to that record.
    BTW, in the sub form "Contract_Frm", the control named Text20, bound to field "Contract_ID" should NOT be visible because "Contract_ID" is an Autonumber type field.


    "when i click the button, i want to create a new record in table "contract_tbl"."
    What data and from where do you want to add to table"contract_tbl"?
    "Anna" is the record in the main form. When I click on the tab "Kontrakt", the list box displays 2 records.
    What now?
    Explain (step by step) what should happen/actions taken if you want to add a new contract record.


  3. #3
    Behedwin is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    61
    when selecting a row in the listbox in profile_frm under tab "Kontrakt" the subform contract_frm should be populated with data from contract_tbl
    The listbox contains a summery of data from contract_tbl
    So when selecting a row in the listbox, it brings up full data in several textboxes in the subform (contract_frm)
    Now i want to create a new record in contract_tbl.
    Click a button in either profile_frm or contract_frm and fill in the textboxes in contract_frm and create a new record.
    a new record is then displayed in the listbox as a new contract to be clicked on and viewed and edited.

    the ID textboxes are visible just for testing now
    when i got things working i will hide them.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Well, you didn't explain (with examples) what should happen/how to "Create a New Employment" (Skapa ny anställning) or what you want to see when the button is pressed. (it really helps us if our questions are answered)

    I changed quite a few things - I don't remember all of them.

    I changed the FK fields in table "Contract_Tbl". They should not have a default value of zero.
    I changed the relations in the relationship window.
    I edited the queries.
    I added/changed the form "sfContract_Frm" (sf prefix = sub form)
    I renamed some controls ...( "txtNew" is a terrible name for a button).



    See if this is close ....
    Attached Files Attached Files

  5. #5
    Behedwin is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Posts
    61
    Thank you. I have found a few solutions already. but i can see some improvements being done based on your changes aswell.

    We might not agree on all things
    for example the relationships i had set were there for a reason (i think) and the names, sure i can have them set to something better

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Behedwin View Post
    We might not agree on all things
    for example the relationships i had set were there for a reason (i think)
    Agreed...

    But here is my reasoning........
    Click image for larger version. 

Name:	Presentation1.png 
Views:	7 
Size:	54.5 KB 
ID:	34647
    The fields in the RED boxes are foreign key (FK) fields. You have a default value of zero set for these fields.
    The primary key (PK) fields in the 3 tables are autonumber type fields. Because the primary key fields are autonumbers, they can never have a value of zero.
    You do not have referential integrity (RI)set for the relationships between tables "Role_Tbl", "Jobbarpa_Tbl" and "Contract_Tbl".
    This allows you the possibility of creating orphan records in "Contract_Tbl".
    So you had to change the join type to be able to see these "orphan" records.


    Removing the default value of Zero from the 5 FK fields in "Contract_Tbl" and changing/fixing the relationships to include RI,
    Click image for larger version. 

Name:	Presentation2.png 
Views:	7 
Size:	61.8 KB 
ID:	34648
    IMHO, results in a better design. No orphan records allowed.


    But this is your dB.... I am just offering ideas that I have found to work for me. I hope this has helped.


    Good luck with your project.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 03-04-2018, 01:15 PM
  2. Replies: 3
    Last Post: 03-09-2017, 08:48 AM
  3. Replies: 4
    Last Post: 09-08-2016, 06:35 AM
  4. Replies: 4
    Last Post: 04-01-2014, 02:33 PM
  5. Replies: 3
    Last Post: 07-01-2011, 12:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums