• Saving A Record (A2K SR1)

    Author
    Topic
    #371804

    I have a form with a subform. The form has a Save button with the following code:

    Private Sub SaveRec_Click()
    On Error GoTo Err_SaveRec_Click

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Me.AllowEdits = False
    Me.AllowAdditions = False
    Me.AllowDeletions = False
    Me.sbfLINEITEMS.Form.AllowAdditions = False
    Me.sbfLINEITEMS.Form.AllowEdits = False
    Me.sbfLINEITEMS.Form.AllowDeletions = False
    Refresh

    Exit_SaveRec_Click:
    Exit Sub

    Err_SaveRec_Click:
    MsgBox “The Save Record function is unavailable because the record was not changed.”
    Resume Exit_SaveRec_Click

    End Sub

    The Save button works as desired if I press it when I’m on the main form. AllowEdits, AllowAdditions, and AllowDeletions get set to False and the form (including the subform) is ‘locked’ again. However, when I press the Save button when I’m in the subform (sbfLINEITEMS), none of the Save button actions occur (AllowEdits, AllowAdditions, and AllowDeletions don’t get set to False for either the main form or the subform). I’ve tried resetting the focus to a control on the main form before the Save actions occur…that didn’t do anything. I know I’m missing something with regard to the interaction betweens forms and subforms, but I don’t know what. Any help would be appreciated. Thank you.

    Viewing 0 reply threads
    Author
    Replies
    • #592182

      I take it that the Access 95 code in the DoCmd line is intended to save the current record? Why not use an updated line instead?

      DoCmd.RunCommand acCmdSaveRecord

      It won’t change your problem, but it will make your code easier to read.

      As to your question, it works properly on my installation of A2k SR1. Is it possible you have something in the Current event of the form that is turning those settings back on again?

      • #592183

        Charlotte,

        I have no Current event running.

        When I use your modified Save code, I get the error message presented in the routine I posted in my original message, even if I do change the record.

        I ran a test using the code from my original post. I placed a message box as the next line after the 6 lines of code resetting the switches. When I press the Save button when I’m in the main form, the message box appears. When I press the Save button when I’m in the subform, the message box does not appear (it looks like the routine is not getting past the SaveRecord command).

        Any help/suggestions would be appreciated. Thank you.

      • #592230

        Charlotte,

        I placed message boxes at the beginning and end of my Save Record routine. When in the main form, the routine works perfectly. However, when in the subform, when I press the Save Record button, absolutely nothing happens (the message boxes don’t appear). I absolutely don’t understand what’s happening. Any suggestions would be appreciated.

        • #592233

          Do you have code in the On Exit event of the subform control, or in the subform itself or any control of the subform that can prevent accessing the saving function ?

          • #592234

            Not that I can see. If you don’t mind, I’ll send you my DB so you can have a look. That way, we can post a cogent solution for everyone to see.

            • #592235

              No problem

            • #592274

              Roy,

              In the subform sbfLineItems, in the after update event of the form, you have the line :
              Forms!frmsubinfo6!SaveRec.Enabled = False
              So when you change a record on this form, and go to the SaveButton, you update the record by leaving the subform and in the after update of the form you set the SaveRec button enabled to false and when you click on it, it is already disabled.
              If you comment this line out, the problem is solved.

            • #592362

              Thanks for all of your help. This solved the problem. I have to try harder to remember what happens when the focus moves between forms and subforms. Thanks, again.

    Viewing 0 reply threads
    Reply To: Saving A Record (A2K SR1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: