Hello David,
If this is a repeat I apologize. I hit a key and my window disappeared. I
don't know if I closed or posted it.
I don't know if this will help, but I just wrote a procedure to track the
uses on a record on a form. It can probably be modified to suit you
purpose, but it it would need to be implemented on each form that reads the
table and wouldn't protect a record from an open table, query or other
access.
I created a logging table to track the users, which includes the Form Name,
User Name, Computer name and RecordID. I would think for your purpose
recordID would suffice.
The API came from the Access Web and was written by Dev Ashish.
I place this code in the Current event of the Form: Some of it doesn't apply
to this, but I am thinking you can figure out what you need.
'****** Record User section
'Clear records in table [ScreenUserIdent] for Logged in Used for this
machine
Call ClearLoggedUsers
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("ScreenUserIdent", dbOpenDynaset,
dbSeeChanges)
If IsNull([ordID]) Or Me.RecordSource = "Order Entry Header Blank" Then
'So records aren't added when no user is logged on
'Exit Sub
GoTo exit_Section
End If
rst.FindFirst "[empLoginName] = '" & GetLoggedUser & "' And
[FormChildLink] = " & [ordID] & " And [MachineName] = '" & fOSMachineName &
"' And [ScreenName] = '" & Me.Name & "'"
If rst.NoMatch Then
rst.AddNew
rst![ScreenName] = Me.Name
rst![EmpLoginName] = GetLoggedUser()
rst![EmpLocation] = getUserLocation()
rst![FullName] = GetLoggedFullName
rst![MachineName] = fOSMachineName
rst![FormChildLink] = [ordID]
rst![TimeLog] = Time
rst.Update
End If
The function ClearLoggedUsers clears the log table, [ScreenUserIdent], the
current user from all records that he is logged into on the current form and
current machine: THis is done first then the new record is created.
Public Sub ClearLoggedUsers()
'On Error Resume Next
Dim strScreenName As Variant
strScreenName = Screen.ActiveForm.Name
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE [ScreenUserIdent].EmpLoginName,
[ScreenUserIdent].MachineName " & _
"FROM [ScreenUserIdent] " & _
"WHERE ((([ScreenUserIdent].EmpLoginName)=getLoggedUser()) AND
(([ScreenUserIdent].MachineName)=fosMachineName()) AND
(([ScreenUserIdent].ScreenName)= '" & Screen.ActiveForm.Name & "'));"
DoCmd.SetWarnings True
End Sub
ClearLoggedUsers is also in the Unload event of the form. This assures that
the user will be cleared whenever the form is formerly closed. If Access
bombs out the user will show as using that record, but that will be remedied
when he opens the form next. You can also provide a maintenence screen to
clear orphan users.
If you have an questions, post back on this thread.
I hope this helps.
God Bless,
Mark A. Sam