Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    79

    Unanswered: Form/Subform Question

    I have a form (frmCustMaster). On it there is a subform (frmSubCustMaster).

    On the frmCustMaster is the Close Button. On Click for this button, I want to check dirty of subform. The code I am trying is.

    If Forms![frmSubCustMaster].Dirty Then
    SaveAnswer = MsgBox("Do you wish to close without saving?", vbQuestion + vbYesNo, "Save Record")
    If SaveAnswer = vbYes Then
    Form.Undo
    DoCmd.Close
    End If
    Else
    DoCmd.Close
    End If

    When I press Close, I get error 'Microsoft Office Access can't find the form 'frmSubCustMaster' referred to in a Macro expression or Visual Basic code.

  2. #2
    Join Date
    Sep 2004
    Location
    Reston, VA
    Posts
    86
    Try this instead, where name_of_subform_control is the name of the actual subform control on frmCustMaster, not the name of the subform object that's bound to the control (so it wouldn't be frmSubCustMaster):

    Code:
    If name_of_subform_control.Form.Dirty Then
      SaveAnswer = MsgBox("Do you wish to close without saving?", _
        vbQuestion + vbYesNo, "Save Record")
        If SaveAnswer = vbYes Then
          name_of_subform_control.Form.Undo
        End If
    End If
    DoCmd.Close
    You don't need the extra else part of the statement, since you want the form to close no matter what, right? Just put it once at the end, after the check to undo the subform.

  3. #3
    Join Date
    Mar 2004
    Posts
    79
    Maybe that's my problem. I was trying to check if the form was dirty not a specific control on the subform.

    Basically, if user changes a value and then tries to close, I want message warning that data has not been saved.

  4. #4
    Join Date
    Sep 2004
    Location
    Reston, VA
    Posts
    86
    The code I posted should do that - name_of_subform_control is not a control on your subform, it's the control on your main form that holds the subform. Referencing a subform in the code of the mother form can be a pain, since you have to distinguish between the name of the subform (what you would see in the Forms group in the Access database window) and the name of the control to which that subform is bound.

    There are different ways to do it, with ! or . operators, but I like the . operators better...that's just me.

    To access the dirty property of the subform, etc, use:

    name_of_subform_control.Form.Dirty

    To get to the dirty property of a control on the subform, it may be easier to handle that in the Form_Close event of the subform itself.
    Last edited by BummerJeff; 10-20-04 at 00:16.

Posting Permissions

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