Results 1 to 8 of 8
  1. #1
    The Professor is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Location
    Cambridgeshire, UK
    Posts
    67

    OnEnter Event

    Hi,

    I have a SubForm as a Control on a MainForm.
    I have code in the SubForm's OnEnter event, which I need to run when a New Record is created - either in the MainForm, or in the SubForm.



    What other events would trigger the OnEnter event? Is it triggered only when a New Record is generated - or is it triggered every time the SubForm control is activated?

    Prof?

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    Events do not trigger events - actions do, although some actions can trigger more than one event

    See this link for more information on what events occur in what order

    https://support.office.com/en-ca/art...7-ce86553682f9

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    dont use ON ENTER
    use BEFORE UPDATE
    this can examine the data bfore you save.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    OnEnter is triggered when moving to the subform control. https://msdn.microsoft.com/en-us/lib...or=-2147217396

    Exactly what do you want to happen? What is the code?
    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.

  5. #5
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    dont use ON ENTER
    subform controls only have enter and exit events

  6. #6
    The Professor is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2012
    Location
    Cambridgeshire, UK
    Posts
    67
    Quote Originally Posted by June7 View Post
    Exactly what do you want to happen? What is the code?
    Hi, Thanks everyone.

    What I want is, each time a New Record is created I want to run a small piece of code that will update a field on the SubForm. I don't want the code to run unless it is a New Record.

    It had been suggested to me that I place the code in OnEnter event of the SubForm, but I'm not too sure this is the right place for it. I know I can probably use, If Me.NewRecord Then, to test for a New Record, then execute the code, but which SubForm event is the best to place for this code? I'm now thinking not OnEnter?

    Prof

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    If you want the code to run when a New Record is entered into the Main Form, the code will have to placed in the Main Form. When moving from a Main Form to a Subform, the Main Form Record is saved and hence is no longer a New Record.

    But in order to really advise you, you need to answer the questions

    Quote Originally Posted by June7
    Exactly what do you want to happen? What is the code?
    Linq ;0)>

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Try the main form AfterUpdate event.

    If Me.NewRecord Then
    'do something with the subform
    End If
    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. Replies: 12
    Last Post: 03-16-2015, 04:57 PM
  2. Replies: 7
    Last Post: 05-08-2014, 10:34 AM
  3. Replies: 1
    Last Post: 03-29-2014, 07:46 PM
  4. Replies: 3
    Last Post: 05-07-2012, 12:17 PM
  5. Replies: 21
    Last Post: 06-03-2009, 05:54 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