Why Me.Requery fails inside After_Insert?

prabha_friend

Prabhakaran Karuppaih
Local time
Today, 22:01
Joined
Mar 22, 2009
Messages
1,036
Rich (BB code):
Private Sub Form_AfterInsert()
Dim CurrentTransDate As Date
CurrentTransDate = Me.DateVal.Value
Dim Transet As Recordset
Set Transet = CurrentDb.OpenRecordset("SELECT Amount FROM Transactions where To=" & Me.To.Value & " AND Head=" & Me.Head.Value & " AND DateVal<#" & Format(CurrentTransDate, "mm/dd/yyyy hh:mm:ss") & "#;")
'Basic Pay
Dim BasicPay As Currency
With Transet
    If .EOF = True Then
        BasicPay = 100000
        Me.DateVal.Value = Format(#1/1/2020#, "mm/dd/yyyy hh:mm:ss")
    Else
        .MoveLast
        BasicPay = Transet.Fields("Amount").Value
    End If
End With
Me.Amount.Value = BasicPay

'Hikes
Dim HikeStatus As Boolean
HikeStatus = IIf(DCount("ID", "Hikes", "Effective_Date<#" & CurrentTransDate & "#") > 0, False, True)
If Not HikeStatus = True Then
    Dim Hikeset As Recordset
    Set Hikeset = CurrentDb.OpenRecordset("SELECT Percentage, Status, Effective_Date FROM Hikes where Staff=" & Me.To.Value & " AND Record_Date<=#" & Format(CurrentTransDate, "mm/dd/yyyy hh:mm:ss") & "# AND Status = FALSE" & ";")
    With Hikeset
        If Not .EOF = True Then
            .MoveLast
            BasicPay = BasicPay + (BasicPay * .Fields("Percentage").Value)
            
            'Arrears
            Dim ArrearStatus As Boolean
            ArrearStatus = IIf(DCount("ID", "Transactions", "To=" & Me.To.Value & " AND DateVal<#" & CurrentTransDate & "# AND Head=30") > 0, True, False)
            If ArrearStatus = False Then
                CurrentDb.Execute ("INSER-T INTO Transactions (To,Head,Amount) VALUES (" & Me.To.Value & "," & 30 & "," & (BasicPay + (BasicPay * Hikeset.Fields("Percentage").Value)) * (DateDiff("m", Hikeset.Fields("Effective_Date"), CurrentTransDate)) & ");")
                Me.Requery
                With Hikeset
                    .Edit
                    .Fields("Status").Value = True
                    .Update
                End With
            End If
        End If
    End With
End If
Me.Amount.Value = BasicPay
DoCmd.Save
Me.Requery
End Sub
 
I just successfully ran this code in a form...
Code:
Private Sub Form_AfterInsert()
    Me.Requery
End Sub
... so I cannot confirm your claim that Requery fails inside of AfterUpdate. Maybe remove all your code, then add it back one section at a time, and see if the code you are running is affecting the outcome.
 
@prabha_friend - can you be more specific as to why you say your .Requery fails? What did you expect to see but didn't see? What message or visible result of data-record result did you get to make you think it failed? Showing us code without knowing its purpose is not really conducive to problem solving.
 

Users who are viewing this thread

Back
Top Bottom