default code for Save button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Whasigga
    New Member
    • Oct 2007
    • 11

    #1

    default code for Save button

    Hi

    I've created a form that has 7 subforms. It is the same subform, bound to a table, just repeated. This form represents a week, and each subform is used to enter in data for each day of the week. The main form has a combo box that must have a value selected before anything else can happen. Once that value is selected, the 7 subforms are enabled, and also one of the fields is populated with the value from the main form. These subforms also have a combo box with a default value, and a text box with a default value, along with the field from the main form.

    My main form has a save button, which I created just using the button wizard and default code. It also has a Close button, also created with the wizard.

    My issue is that when I use the save button, if none of the subforms have been changed from the default values, none of them get saved. If a default value is changed, then that record corresponding to that subform is saved, but the others arent.

    My Close button saves each of the subforms and their records, even if the defaults have not been changed.

    Is that a part of the Save button that Access creates, that it will only save updated things? When the main form populates each of the subforms, they all create new entries in the table, the primary key is autonumber, so they are different records, but they dont get saved unless the default values are changed... and I'm not sure why

    thanks
    Josh
  • nico5038
    Recognized Expert Specialist
    • Nov 2006
    • 3080

    #2
    Why don't you insert all seven rows when the weeknumber is determined or e.g. in the OnOpen event of the form. Just check there are no rows for that week and INSERT them.

    Nic;o)

    Comment

    • Whasigga
      New Member
      • Oct 2007
      • 11

      #3
      thanks for the suggestion

      The primary key for the table with subforms is based on the day and an employeeID. The day is autopopulated, but the employeeID is not set in the form until the user chooses which one. So I dont think it could be inserted without the rest of the key identified...of course I could be wrong about that.

      Josh

      Comment

      • nico5038
        Recognized Expert Specialist
        • Nov 2006
        • 3080

        #4
        So you'll need to use the combo's AfterUpdate event to insert the seven rows when not yet present.
        So effectively the user is updating these rows instead of creating new records.
        The "cost" is however that you'll have to DELETE the rows when the user presses the [Cancel] button.

        Clear ?

        Nic;o)

        Comment

        • Whasigga
          New Member
          • Oct 2007
          • 11

          #5
          oh, yea that makes sense.

          thanks for your help on this

          Comment

          Working...