Best Practice Needed - Form.AfterUpdate for mouse click away

Nyanko

Registered User.
Local time
Today, 07:54
Joined
Apr 21, 2005
Messages
57
Hi,

I have a date entry field that I need to fire an action once the field is completed. I was using a Form.AfterUpdate event to do this, but my end users reported it wasn't working...

Private Sub FormProjectCode_AfterUpdate()


after looking here : https://msdn.microsoft.com/en-us/library/office/ff822097.aspx

It states that "The AfterUpdate event is triggered when a control or record is updated. Within a record, changed data in each control is updated when the control loses the focus or when the user presses ENTER or TAB."

My end user prefers to navigate by mouse clicking on the next field rather than tabbing (go figure). How can I capture leaving this field when it is complete, regardless of how the user leaves ?

OnChange/OnDirty/LostFocus ?

Which is the best practice in this situation ?
 
use the textbox control's afterupdate event.
what is the reason why you want to capture any update on the said textbox?
if fires when you tab or use mouse click on changing record.
 
I'm using the after update to create a corresponding record in a different table which is displayed in a sub tab.

Code:
Private Sub FormProjectCode_AfterUpdate()
'------------------------------------------------------------
' This code fires after the project code has been entered on the Invoice Detail form.
' It adds a new line to the debt tracker table/subform
'------------------------------------------------------------
Dim StrSQL As String

If Nz(DCount("*", "tbl_DebtTracker", "RowID=" & Me!FormRowID), 0) > 0 Then
        ' If record found then perform update query
        StrSQL = ""
        StrSQL = StrSQL & " UPDATE tbl_DebtTracker"
        StrSQL = StrSQL & " SET RecordID=(""" & Me!FormRecordID & """)"
        StrSQL = StrSQL & " WHERE RowID = (" & Me!FormRowID & ")"
        CurrentDb.Execute StrSQL
    
    Else
        ' If record not found then perform insert query
        StrSQL = ""
        StrSQL = StrSQL & " INSERT INTO tbl_DebtTracker"
        StrSQL = StrSQL & " (RowID,RecordID)"
        StrSQL = StrSQL & " VALUES"
        StrSQL = StrSQL & " (" & Me!FormRowID & "," & Me!FormRecordID & ");"
        CurrentDb.Execute StrSQL
    End If

Me.Refresh
Me.FormScheduledDate.SetFocus
End Sub

I need to be able to refresh the subform which is held in on a different tab, as at the moment when you click on the tab for the subform it doesn't show as updated even though the data has been written into the table.

The above code is written into

Tab_Invoice - frm_MainInputSub - FormProjectCode

I need to refresh

Tab_DebtTracker - frm_MainInputDebt

Any advice welcome
 
before the end of your sub, try adding this line to refresh the subform:

Me.frm_MainInputDebt.Form.Requery
 

Users who are viewing this thread

Back
Top Bottom