Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BeforeUpdate event interferes with Record Navigation

Status
Not open for further replies.

mtnsurfer22

Programmer
Apr 13, 2002
19
US
I have written some code in the BeforeUpdate event of a form that will search all of the control boxes on the form and record any changes to those controls to another table (tblChanges) along with other relevant info. My problem is that when I use the standard record navigation buttons (which calls the BeforeUpdate event like I need it to) my changes are tracked to the table fine but the form never updates and continues to the the next record. The navigation buttons seem to simply just call my BeforeUpdate event and then "forget" about their other task of record navigation.

My guess is that it has something to do with my setting the focus to each control as I search for changed records. Perhaps this new focus is interfering with the exit and LostFocus events that need to occur next. However, I can't seem to access the properties of the current control unless it has the focus. I will paste my code below, any suggestions would be greatly appreciated.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctlC As Control
Dim rs As DAO.Recordset
Dim Index As Integer

Set rs = CurrentDb.OpenRecordset("tblChanges")

For Each ctlC In Me.Controls
If ctlC.Tag = "record" Then
ctlC.SetFocus
If ctlC.Text <> ctlC.OldValue Then
rs.AddNew
rs!UsersID = Me.UsersID
rs!Date = FormatDateTime(Date, vbShortDate)
rs!PreviousValue = ctlC.OldValue
rs!NewValue = ctlC.Text
rs!Field = ctlC.Name & &quot; -> &quot; & Me.Name
rs.Update
End If
End If
Next ctlC
End Sub


thanks
Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top