Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2004
    Posts
    115

    Unanswered: Insert records into 2 tables

    I would like to insert records into 2 tables after I select a record from the drop down.

    In the main form there is a dropdown where you can select a Group type.

    I need the code of how to insert (create) new records for the existing order as follows.

    Insert a record for the selected Group type, into tblOrderDetails
    Then, Insert part records tblOrderSubDetails, based on tblGroupType.DefaultPartNumbers for the selected Group type.

    Can you please share the insert statement that I need?

    I know it’s not written clear, but I believe if you open the sample DB, you will understand what I need.

    Thanks
    Attached Files Attached Files

  2. #2
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    495
    Provided Answers: 24
    just run an append query. Use the keys of the record you are on.
    then they will show up after the refresh.

    docmd.openquery "qsAdd2Rescs"
    subform.requery

  3. #3
    Join Date
    Jan 2004
    Posts
    115
    Thanks for the response.
    It needs to first create a record in tblOrderDetails and then into tblOrderSubDetails (and populate in tblOrderSubDetails the new generated record number from tblOrderDetails)

    Where can I see the "qsAdd2Rescs" query?


    Thanks

  4. #4
    Join Date
    Jan 2004
    Posts
    115
    I have never made such an insert. Can anyone please help write this insert sql? As mentioned above, I believe if you open the sample DB, you will understand what I need. Thanks

  5. #5
    Join Date
    Feb 2013
    Posts
    99
    Morning Tom

    You could use the following,

    If me.dropdownbox.value = "GroupType1" then

    DoCmd.SetWarnings False
    DoCmd.RunSQL "INSERT INTO Yourtablename (Field1,Field2,Field3) VALUES ('Value1','Value2','Value3')"
    DoCmd.SetWarnings True

    Elseif me.dropdownbox.value = "GroupType2" then
    DoCmd.SetWarnings False
    DoCmd.RunSQL "INSERT INTO Yourtablename (Field1,Field2,Field3) VALUES ('Value1','Value2',Value3')"
    DoCmd.SetWarnings True
    exit Sub

    End if

    End Sub

    You will need to replace the text in bold with your data, also depending on what your Value is will depend on how it is defined in the Value of the Docmd.runsql insert into section.

    For Example

    If it is Text then as follows 'Text'
    If it is True or False then " & True & "
    If it is a tempvar or field then '" & TempVars!Var & "'

    Hope this makes sense,

    Kind Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •