Results 1 to 9 of 9
  1. #1
    acannon is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Birmingham, AL
    Posts
    16

    Angry Can't create new record in a related table

    I am building an application for tracking equipment on engineering projects. The db contains a table EqBasic which contains basic information about every equipment item in the project. There are also related tables that contain details about the equipment items. There are different related tables depending upon the type of equipment item.



    I use a command button on the form for displaying/entering the basic info to add a new item, and that works well. Currently I have to manually create the record in the related detail table, but am trying to tie that process into the process of creating the new record in the basic table. So far I have no success at all. I can get the form for entering the details of the related item to open, and navigate to a new record, but nothing I have been able to do will allow me to programmatically put the necessary entry into the 2 fields used as a compound unique index to relate the 2 tables. The 2 fields for the unique index are 2 of the 3 fields that are concatenated for a complete equipment number. I have no issue entering them into the new record in the basic table, but can’t get them into the new record in the related table using VBA.

    Any help will be greatly appreciated! I’ve been pulling out what little hair I have left for several days now on this problem.

    Thanks,
    Alan

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You need a form with the single master record.
    in the form add a subForm that links the master key. this will add the Master key automatically to the child table.
    The form wizard will build this for you.

  3. #3
    acannon is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Birmingham, AL
    Posts
    16
    I'll try that, but I don't think it will work. I have 9 different related tables which have different data in them depending on the type of equipment item. Any given equipment item has 1 record in the basic info table and 1 record in only 1 of the 9 related detail tables. I think I've found a way to do what I'm attempting with SQL code and the DoCmd.RunSQL functionality.

    I'll post back the results of both efforts.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Then you can have 9 different subforms organized on a Tab control.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    acannon is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Birmingham, AL
    Posts
    16
    Thanks for the suggestions. I found the DoCmd.RunSQL approach worked very nicely. I used a Select Case structure to set the first part of the SQL string of "INSERT INTO {tablename}, then completed the common part of the SQL string outside the Select Case. It works just fine and I didn't have to revise or create any additional forms.
    Thanks again to both of you! ... Alan

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Glad you found solution.

    But I am wondering - isn't there other data that must be input to the detail tables?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    acannon is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Birmingham, AL
    Posts
    16
    Yes, there is other data for the detail tables, but this action simply creates the record in the detail tables. Typically we will enter the basic data at the start of the project, then as detailed info is developed we add the detailed information. I had encountered the problem that the record didn't exist in the detail table to enter the data and this way my users don't have to know how to create the record. It is automatically created when the basic equipment record is created.

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    And how is more data entered into the 9 detail tables - a single form that has all 10 tables in the RecordSource?

    Sounds like my db is similar - main table with multiple 1-to-1 related tables but not every detail table will have an associated record. I have a 'login' form for the main table and use VBA to create related record(s). Then a single form with all the tables in the RecordSource for detail data entry.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    acannon is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Birmingham, AL
    Posts
    16
    The primary form, which is the basic info form, has a command button that will open the appropriate detailed form to the record for the current record in the basic form. A command button closes the detail form and returns to the basic form. There is also an alternate path to the detail form, and the command button code is able to detect the correct calling form and return to the one from which it was called.

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

Similar Threads

  1. Replies: 15
    Last Post: 03-05-2015, 03:30 PM
  2. Add sum of data to a record related in another table
    By Rafegh in forum Database Design
    Replies: 6
    Last Post: 11-14-2014, 02:55 PM
  3. Replies: 40
    Last Post: 08-20-2013, 11:38 PM
  4. Replies: 0
    Last Post: 09-17-2012, 03:35 PM
  5. Replies: 7
    Last Post: 07-02-2012, 10:50 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