I have a form based on an Access database. The database has a main table (called tblRequests) to which users can submit data. The main table has a one to many with a second table (repeating table called lkpComments). On my form I show one record from the main table, and many records (comments) from the second table). Users can add comments at will, but I want to prevent a user from deleting a comment that belongs to someone else. Therefore, my comments table includes a field titled "CommentBy" which holds the name of the person who originally entered it.
I want to be able to compare the current UserName with the name in the CommentBy field of the repeating table entry that currently has focus so that I can prevent it's deletion.
This is what I have so far, but there is something wrong with my reference to the @CommentBy field. (I think it is because I need to somehow refer to the specific "comment" entry that has the focus).
Any ideas? Thanks!
function msoxd_d_lkpComments::OnBeforeChange(DataDOMEvent)
{
//determine the current user
var oNetwork = new ActiveXObject("WScript.Network");
var strUserName = oNetwork.UserName;
//check to see if the current user is the owner of the comment
if (strUserName == XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:tblRequests/lkpComments/@CommentBy").text)
{
//allow deletion of the record
}
else
//prevent deletion of the record
if (DataDOMEvent.Operation == "Delete" && DataDOMEvent.Site == DataDOMEvent.Source && DataDOMEvent.NewValue == null)
{
DataDOMEvent.ReturnStatus = false;
DataDOMEvent.ReturnMessage = "You cannot delete this record";
}
}