none
How to detect when a subform is displayed RRS feed

  • Question

  • MS Access 2016, I have a form with an subform.  The main form is displayed in Datasheet View.  Is there a way to detect when the subform is displayed and when it has closed?  

    I want to display an message when the subform is initially opened and then an another message when it's closed.  Can this be done?

    TIA

    Saturday, February 16, 2019 10:36 PM

Answers

  • OK now it makes more sense.

    First, 'Name' is a reserved word in ACCESS so you should never use it as a field name. So if you have a field name in a table called 'Name', you should change it to something else like ClientName or CustomerName.

    Second, the SubForm will always be available of editing anyway so there is no reason for its data to have to be displayed only when you select a CustomerName. It will be displayed anyway. You also don't need an Update button. If you enter data into the Subform, it should update as long as its Enabled property is set to 'Yes' and its Locked property is set to 'No'.

    Third, You can use:

    DoCmd.RunCommandacCmdUndo

    to Undo entries. Just put the command in the buttons On Click Event Procedure.

    • Marked as answer by PSD1953 Monday, February 18, 2019 2:02 AM
    Monday, February 18, 2019 12:23 AM

All replies

  • You mean whether the Subdatasheet is open or closed? I don't think there is a documented way to do that.

    -Tom. Microsoft Access MVP

    Sunday, February 17, 2019 4:11 PM
  • A SubForm is simply another control type on a form and is opened automatically when the parent form is opened. You can set its visible and enabled properties or display a message when its opened using the SubForms On Open Event, but cannot "close" it as you are using the term.

    Sunday, February 17, 2019 5:51 PM
  • Interesting. Wonder if I can monitor and track if the subform is visible (expanded) or not..  

    Can the control option "SubdatasheetExpanded" help?  So far I've not found a way.  Need to do more research.

    TIA,

    Sunday, February 17, 2019 10:01 PM
  • A Subform is always visible unless you write a macro or VBA code to set its Visible property to False. Why don't you share with us why you would want to monitor or track whether a Subform is visible or not. Like I said, unless you or someone else re-sets its visible property, it will always be visible on the parent form. Do you want it to be not visible if there is no data for it to display? If so, we can tell you how to do that, but right now I am at a loss as to your ultimate goal.

    Sunday, February 17, 2019 10:39 PM
  • I agree with you.  I need to better describe my goal.  Maybe you can show me the better way.

    A good example is a table that contains phone contact information.  “Name, Address, Phone, Sex, etc…”.  There are over 20 unique fields.

    I want to display the names in the primary datasheet form, and then when a name is selected the remaining data is displayed in the subform for editing.

    I want to be able to update the subform data, but be allowed to ‘undo’ the update.   Is there an easy way?  I’ve added two buttons to the subform footer – “Cancel” and “Update” but unsure how to make this happen.

    Sunday, February 17, 2019 11:18 PM
  • OK now it makes more sense.

    First, 'Name' is a reserved word in ACCESS so you should never use it as a field name. So if you have a field name in a table called 'Name', you should change it to something else like ClientName or CustomerName.

    Second, the SubForm will always be available of editing anyway so there is no reason for its data to have to be displayed only when you select a CustomerName. It will be displayed anyway. You also don't need an Update button. If you enter data into the Subform, it should update as long as its Enabled property is set to 'Yes' and its Locked property is set to 'No'.

    Third, You can use:

    DoCmd.RunCommandacCmdUndo

    to Undo entries. Just put the command in the buttons On Click Event Procedure.

    • Marked as answer by PSD1953 Monday, February 18, 2019 2:02 AM
    Monday, February 18, 2019 12:23 AM