Results 1 to 4 of 4
  1. #1
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614

    Nested Subform's control events

    Forms : Main------>SubForm1------>Subform2
    Controls : Main ------->SupplierName
    SubForm2-------->Product
    The Product combo on SubForm2 has list of products based on SupplierName on MainForm. If the user does not select the supplier name, the Product combo will not have any data. I am trying to prompt the user to select Supplier in such case. The following code achieves the required result but ....

    Code:
    Private Sub Product_GotFocus()
    If IsNull(Forms!Main!SupplierName) = True Then
    MsgBox "Select supplier name", vbInformation Forms!Main.SupplierName.SetFocus Forms!Main.SupplierName.Dropdown
    End If End Sub

    Problem : If the user leaves the SupplierName blank and then clicks on any of the controls on SubForm1 or SubForm2, the above code continues to execute till SupplierName is selected.
    How to prevent repeated execution of the above code except when the Product combo on SubForm2 has focus?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    That seems odd. The code should not trigger if other controls are clicked.

    An alternative is to not make the subform available until SupplierName is selected.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    June7, thanks for the suggestion. Your alternative will certainly sort out the problem.

    This is from the MSDN http://msdn.microsoft.com/en-us/libr.../ff836988.aspx for the subform's exit event.

    "If the control you move to on the subform previously had the focus, neither its Enter event nor its GotFocus event occurs, but the Enter event for the subform control does occur. If you move the focus from a control on a subform to a control on the main form, the Exit and LostFocus events for the control on the subform don't occur, just the Exit event for the subform control and the Enter and GotFocus events for the control on the main form."

    I think when the user leaves SupplierCombo on mainform null and then clicks anywhere on the sub form1 or subform2 the last control that had focus was the product combo on subform2.Hence, the code executes repeatedly.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,900
    I did a test of that scenario and yes, the combobox GotFocus event triggers when returning to the subform if the combobox held focus when clicking out of the subform. Would not have thought that but I guess does make a kind of sense. Learn something new every day.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Delete record from nested subform
    By raton in forum Forms
    Replies: 1
    Last Post: 04-14-2012, 11:39 AM
  2. Replies: 3
    Last Post: 03-29-2012, 12:40 PM
  3. Replies: 7
    Last Post: 07-15-2011, 08:14 AM
  4. Can't Find Subform Events
    By vdanelia in forum Forms
    Replies: 4
    Last Post: 02-28-2011, 02:23 PM
  5. Replies: 0
    Last Post: 12-28-2009, 12:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums