Form_Current() event executing twice. (1 Viewer)

JGalletta

Windows 7 Access 2010
Local time
Today, 09:36
Joined
Feb 9, 2012
Messages
149
I have an interesting issue where one of my subform's Current event is executing twice. Here is the event:
Code:
Private Sub Form_Current()


DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE tblFieldListPopulation.[Field Number] FROM tblFieldListPopulation"
DoCmd.RunSQL "INSERT INTO tblFieldListPopulation ( [Field Number] ) SELECT tblFieldInformation.[Field Number] FROM tblFieldInformation"
DoCmd.RunSQL "DELETE tblFieldListDeletion.[Field Number] FROM tblFieldListDeletion"
DoCmd.RunSQL "INSERT INTO tblFieldListDeletion ( [Field Number] ) SELECT tblFieldRecJoin.[Field Number] FROM tblFieldRecJoin WHERE (((tblFieldRecJoin.[Record Number])=[Forms]![frmScoutingRecords]![Record Number]))"
    If CurrentDb.TableDefs("tblFieldListDeletion").RecordCount > 0 Then
        Dim MySQL As String
        MySQL = "DELETE tblFieldListPopulation.[Field Number] FROM tblFieldListPopulation Where tblFieldListPopulation.[Field Number] IN ("
        Dim r As DAO.Recordset
        Set r = CurrentDb.OpenRecordset("Select * From tblFieldListDeletion")
        
            r.MoveFirst
            Do Until r.EOF = True
                MySQL = MySQL & "'" & r![Field Number] & "', "
                r.MoveNext
            Loop

        r.Close
        Set r = Nothing
    MySQL = Left(MySQL, (Len(MySQL) - 2)) & ")"
    DoCmd.RunSQL MySQL
    End If
DoCmd.SetWarnings True
Me.FieldNo.Requery

If IsNull(Me.FieldNo) Then
    'MsgBox ("frmFieldRecJoin_Current Field is Null")
    Me.Text79 = Me.JoinPK
    Forms!frmScoutingRecords!Text58.ControlSource = "='  Pest List'"
    Forms!frmScoutingRecords!Child49.SourceObject = "frmBlankPestDetail2"
    Forms!frmScoutingRecords!Child60.SourceObject = "frmBlankPestDetail"
Else
    'MsgBox ("frmFieldRecJoin_Current Field is NOT Null")
    Me.Text79 = Me.JoinPK
    Forms!frmScoutingRecords!Child49.SourceObject = "frmFieldRecInfo"
    Forms!frmScoutingRecords!SRJoinPK = Me.JoinPK
    Forms!frmScoutingRecords!Text58.ControlSource = "='  Showing Pests for Field ' & DLookup('[Field Number]', '[tblFieldRecJoin]', '[JoinPK] = ' & [Forms]![frmScoutingRecords]!SRJoinPK) & '.'"
    Forms!frmScoutingRecords!Child49.Form.Filter = "[JoinPK] = " & Forms!frmScoutingRecords!SRJoinPK
    Forms!frmScoutingRecords!Child49.Form.Requery
End If



End Sub

Can anyone identify what might be making this event execute twice?
 

JHB

Have been here a while
Local time
Today, 15:36
Joined
Jun 17, 2012
Messages
7,732
Maybe the "Me.FieldNo.Requery", try with Me.FieldNo.Refresh or Me.FieldNo.Recalc.
 

spikepl

Eledittingent Beliped
Local time
Today, 15:36
Joined
Nov 3, 2010
Messages
6,142
THis is difficult to guess.

1. What is the name of the form/subform whose current event we are looking at ?
2. You seem to suspect that some code inside the current event handler triggers the re-run of the currrent event. Then start commenting code out until that behaviour ceases. Or not. This would prove/disprove your suspicion.
 

JGalletta

Windows 7 Access 2010
Local time
Today, 09:36
Joined
Feb 9, 2012
Messages
149
I'm doing the commenting now, and I'm getting somewhere (I just don't know where...). It seems to be an issue with editing another subform and returning back to the subform that triggers the event. The subform that triggers the event is frmFieldRecJoin, located in Child20 of the Main form. I think I will be able to figure this out with the commenting. It's just a strange behavior to me since nothing is looped (besides the SQL string builder and I'm positive that is not triggering the second call of the Current event).
 

Users who are viewing this thread

Top Bottom