When data is added to one form, an "event" must be triggered in another one

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neelsfer
    Contributor
    • Oct 2010
    • 547

    When data is added to one form, an "event" must be triggered in another one

    I use the recordset method to add data to a form called frmchipxc and the table involved is called RaceEntry2. When data is added here, i want to run another function in a subform called "RaceTimingKPSF ".The mainform is called "Racesetupx cf". This function deletes duplicate data added in the last 3 minutes to the same table, called "raceentry2 " after data has been added.
    How do i activate/fire this function in the 2nd form as soon as the table (Raceentry2) receives new data via the "frmchipxc" form. I don't want to use the timer function in the subform as the mouse keeps "flickering " on the main form.
    Code:
    Dim rs1 As Recordset
    Dim myRaceTime As Date, myRaceNo As String, x As Long
    DoCmd.SetWarnings False
    DoCmd.OpenQuery "DeleteBlankXCEntries"
    DoCmd.SetWarnings True
    Set rs1 = CurrentDb.OpenRecordset("RaceEntry2", dbOpenDynaset)
    
    x = 0
    rs1.MoveFirst
    With rs1
        Do Until .EOF
            myRaceNo = !RaceNo   'racenumber is a numberfield type
            myRaceTime = !RaceTime
            .MoveNext
                Do Until .EOF
                        If (!RaceNo = myRaceNo) And _
                            (DateDiff("n", myRaceTime, !RaceTime) > -3 And _
                            DateDiff("n", myRaceTime, !RaceTime) < 3) Then
                                .delete
                        End If
                            .MoveNext
                Loop
                    .MoveFirst
                    x = x + 1
                    .Move x
        Loop
    End With
    rs1.close
    Set rs1 = Nothing
    'DoCmd.SetWarnings False
    
    [Forms]![Racesetupxcf]![RaceTimingKPSF].Requery
    [Forms]![Racesetupxcf]![RaceresultsXCSF].Requery
    [Forms]![Racesetupxcf]![SortXcCatSF].Requery
    [Forms]![Racesetupxcf]![Rt_editXCSF].Requery
    Please assist
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    The function must declared as public, and you should then be able to call it like so in the AfterUpdate event of your form:

    Code:
    Call Forms!Racesetupxcf!ControlNameOfSubFormContainer.Form.FunctionName

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      Another way is to treat the forms as class modules; thus, you can create a custom event within the declaration section of the form:



      The book "MS Access 2003 Inside and Out" has an example how to do this on page 906 thru 909...

      Cool thing here is you can sync any open form to each other by using and declaring the events...

      -z
      Last edited by zmbd; Sep 3 '12, 10:55 AM.

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        Sounds a bit like overkill to me. Im sure its usefull but I see no reason going down that road as long as the built in events are fine. Seems you would be re-inventing the wheel so to speak.

        Comment

        • neelsfer
          Contributor
          • Oct 2010
          • 547

          #5
          thx for the help with this problem

          Comment

          Working...