Benginner2212
Member
- Local time
- Today, 15:27
- Joined
- Apr 6, 2023
- Messages
- 52
Thank you for the explanation, I think that I am following the code better.
One question that I still have is the line If IsNull(Me.cboDeptName.OldValue) just checking to see if there was a value saved to the table? If so is that a kind of validation check?
In the event that there is a Dept Name recoreded to a table:
When the form is loaded, any data that is recorded on the table is populated in the corresponding field on the form . In this case, the form loads, the data that is recorded to the cboDeptName is populated on the form in the corresponding field and access moves on to the next part of the loop because the IsNull statement is false. Then if the user doesn't make any changes to cboDeptName field on the form, the If Me.cboDeptName = Me.cboDeptName.OldValue is true because there was no change to the .Text buffer which means that the .Value buffer is unchanged and access exits the loop.
If the users makes a change to the cboDeptName field on the form and user clicks away from the cboDeptName box, the .Text buffer copies the change to the .Value buffer and cboDeptName is no longer equal to the .OldValue buffer. Access displays the message that the Dept Name can't be changed, cancels the update, undoes the change to the cboDeptName, sets the focus back to the cboDeptName field and exits the before update event.
Code:
If IsNull(Me.cboDeptName.OldValue) Then
Else
If Me.cboDeptName = Me.cboDeptName.OldValue Then
Else
MsgBox "Dept Name may not be changed after record is saved.", vbOKOnly
Debug.Print Me.cboDeptName
Cancel = True
Me.Undo
Me.cboDeptName.SetFocus
Exit Sub
End If
End If
One question that I still have is the line If IsNull(Me.cboDeptName.OldValue) just checking to see if there was a value saved to the table? If so is that a kind of validation check?
In the event that there is a Dept Name recoreded to a table:
When the form is loaded, any data that is recorded on the table is populated in the corresponding field on the form . In this case, the form loads, the data that is recorded to the cboDeptName is populated on the form in the corresponding field and access moves on to the next part of the loop because the IsNull statement is false. Then if the user doesn't make any changes to cboDeptName field on the form, the If Me.cboDeptName = Me.cboDeptName.OldValue is true because there was no change to the .Text buffer which means that the .Value buffer is unchanged and access exits the loop.
If the users makes a change to the cboDeptName field on the form and user clicks away from the cboDeptName box, the .Text buffer copies the change to the .Value buffer and cboDeptName is no longer equal to the .OldValue buffer. Access displays the message that the Dept Name can't be changed, cancels the update, undoes the change to the cboDeptName, sets the focus back to the cboDeptName field and exits the before update event.