Results 1 to 7 of 7
  1. #1
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46

    Event on AfterUpdate and creation of new record

    I have an event setup on the AfterUpdate of an Option Group which hide/unhide a bunch of other fields.



    When creating a new record the fields are visible if the previous report I was on had them displayed and I understand that this is because my event is trigged by the AfterUpdate of a field that I have yet not touch on a new record.

    Where should I create such event for it to "reset" on a new record?

    This is my code:

    Code:
    Private Sub Substantive_Stds_AfterUpdate()
    On Error GoTo Substantive_Stds_AfterUpdate_Err
        DoCmd.SetProperty "Selection", acPropertyVisible, "0"
        DoCmd.SetProperty "Subs rectangle", acPropertyVisible, "0"
        DoCmd.SetProperty "12(1)(a) cb", acPropertyVisible, "0"
        DoCmd.SetProperty "12(1)(b) cb", acPropertyVisible, "0"
        DoCmd.SetProperty "Character cb", acPropertyVisible, "0"
        DoCmd.SetProperty "Poo cb", acPropertyVisible, "0"
        DoCmd.SetProperty "12(1)(b) other cb", acPropertyVisible, "0"
        DoCmd.SetProperty "12(1)(c) cb", acPropertyVisible, "0"
        DoCmd.SetProperty "Confusion cb", acPropertyVisible, "0"
    
        If (Substantive_Stds = 2) Then
            DoCmd.SetProperty "Selection", acPropertyVisible, "-1"
            DoCmd.SetProperty "Subs rectangle", acPropertyVisible, "-1"
            DoCmd.SetProperty "12(1)(a) cb", acPropertyVisible, "-1"
            DoCmd.SetProperty "12(1)(b) cb", acPropertyVisible, "-1"
            DoCmd.SetProperty "Character cb", acPropertyVisible, "-1"
            DoCmd.SetProperty "Poo cb", acPropertyVisible, "-1"
            DoCmd.SetProperty "12(1)(b) other cb", acPropertyVisible, "-1"
            DoCmd.SetProperty "12(1)(c) cb", acPropertyVisible, "-1"
            DoCmd.SetProperty "Confusion cb", acPropertyVisible, "-1"
        End If
    
    Substantive_Stds_AfterUpdate_Exit:
        Exit Sub
    Substantive_Stds_AfterUpdate_Err:
        MsgBox Error$
        Resume Substantive_Stds_AfterUpdate_Exit
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    In the Current event you can test for a new record:

    If Me.NewRecord Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    you can also use:

    me.txtBox.visible = false

  4. #4
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46
    So I've tweak my code a bit following both of your recommandations to this:

    Code:
    Private Sub Form_Current()
        If Me.NewRecord Then
            Me.Selection.Visible = False
            Me.[Subs rectangle].Visible = False
            Me.[12(1)(a) cb].Visible = False
            Me.[12(1)(b) cb].Visible = False
            Me.[Character cb].Visible = False
            Me.[Poo cb].Visible = False
            Me.[12(1)(b) other cb].Visible = False
            Me.[12(1)(c) cb].Visible = False
            Me.[Confusion cb].Visible = False
        End If
    End Sub
    
    Private Sub Substantive_Stds_AfterUpdate()
    On Error GoTo Substantive_Stds_AfterUpdate_Err
        If (Substantive_Stds = 2) Then
            Me.Selection.Visible = True
            Me.[Subs rectangle].Visible = True
            Me.[12(1)(a) cb].Visible = True
            Me.[12(1)(b) cb].Visible = True
            Me.[Character cb].Visible = True
            Me.[Poo cb].Visible = True
            Me.[12(1)(b) other cb].Visible = True
            Me.[12(1)(c) cb].Visible = True
            Me.[Confusion cb].Visible = True
            
        Else
        
            Me.Selection.Visible = False
            Me.[Subs rectangle].Visible = False
            Me.[12(1)(a) cb].Visible = False
            Me.[12(1)(b) cb].Visible = False
            Me.[Character cb].Visible = False
            Me.[Poo cb].Visible = False
            Me.[12(1)(b) other cb].Visible = False
            Me.[12(1)(c) cb].Visible = False
            Me.[Confusion cb].Visible = False
    
        End If
    Substantive_Stds_AfterUpdate_Exit:
        Exit Sub
    Substantive_Stds_AfterUpdate_Err:
        MsgBox Error$
        Resume Substantive_Stds_AfterUpdate_Exit
    End Sub
    On the creation of a new record I no longer have the fields display which is a big win... but! Now when i'm cycling through my records I no longer have the fields displayed when it's supposed. Thus I cannot see what I've done on previous record.
    Maybe I just didn't understand well enough what changes to make.

    Basically it just retains the state of the previous record where an update has been done on the Substantive_Stds field

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Perhaps your test should be:

    If Substantive_Stds <> 2 OR Me.NewRecord Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    veejay is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Nov 2018
    Location
    Montreal, Canada
    Posts
    46
    Yes!!! It worked!

    Still trying to understand the order of event triggers and all but I think i'm finally getting there!

    Thanks pbaldy

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. afterupdate event
    By angie in forum Access
    Replies: 2
    Last Post: 04-05-2018, 06:06 PM
  2. Replies: 4
    Last Post: 10-29-2014, 03:49 PM
  3. Replies: 7
    Last Post: 01-02-2012, 06:19 PM
  4. Form AfterUpdate Event
    By RayMilhon in forum Forms
    Replies: 2
    Last Post: 09-09-2011, 09:20 AM
  5. AfterUpdate event help
    By 10 Gauge in forum Forms
    Replies: 11
    Last Post: 09-08-2011, 10:04 AM

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