No announcement yet.

Detail form is only displayed if master form is saved

  • Filter
  • Time
  • Show
Clear All
new posts

  • Detail form is only displayed if master form is saved

    Another strange issue regarding my form application:

    If I click on 'new' or 'copy' in my master form the detail forms aren't displayed, only the the label value of the detail form is displayed (no toolbar, no fields). Now when you click 'insert' on the master form everything is fine.
    Why aren't the detail forms displayed correctly before saving the master form for the first time?


  • #2
    Because the new or copied data has not yet been committed to the database, so any auto increment key fields etc are not available at that point.

    So you either create a new master - commit it - and then open the record again to add the details (perhaps hide the detail blocks until a master key is known) - kind of what you are already describing above.


    You commit the master at creation time. You can do this by creating your own Add button and create and commit the master record with something like below (if MySQL), using a global variable to track the new ID:

    $insert_sql = "INSERT INTO tblxxxx VALUES (NULL,1,1,1,1,0,NULL,NULL)";  // Enough defaults to create the record, but first col is NULL which in my case is the AI key field - so will auto create a new ID there
    sc_exec_sql($insert_sql);    // Run the SQL
    sc_commit_trans();     // Commit the INSERT
    sc_lookup(sc,"SELECT LAST_INSERT_ID()");	// Get newly genn'd Key
    sc_redir(your_master_detail_form_name, NewID=$sc[0][0]);     // Redirect to master/detail form using the global variable.
    The source SQL for the master/detail form should then have in the "where condition" box:

    Last edited by adz1111; 06-30-2015, 10:12 AM.


    • #3
      This is brilliant - I will test that!