I have a form displayed in datasheet view where the user can modify all but a few fields. In the form's BeforeUpdate event, i have the following code:
- Private Sub Form_BeforeUpdate(Cancel As Integer)
-
Dim ctrl As Control
-
-
If Me.Dirty Then
-
For Each ctrl In Me.Controls
-
With ctrl
-
If .ControlType = acTextBox Then
-
Debug.Print .Name
-
If .Value <> .OldValue Then
-
.SetFocus
-
Debug.Print .Name, .OldValue, .Text
-
End If
-
End If
-
End With
-
Next
-
End If
-
'Cancel = False
-
'DoCmd.RunCommand acCmdSaveRecord
-
' DoCmd.Save
-
End Sub
-
This is a test to see if I can later save the changed values to another table in the same database, When as a user, I modify the data in several fields and then click the arrow navigation button to move to the next or previous record in the datasheet, the code above runs successfully displaying the field names whose values have changed and the changes as well. However, the record remains in edit mode and does not move to the next or previous record as I expected based on the fact I clicked the Next or Previous navigation button, If I press the button again, it saves the record and moves to the Next or Previous record as usual. As you can see in the code, I tried several ideas to force the save and move, but none produced the expected result.
Anyone have any idea why?