Understandable documentation regarding Access DBA security

  • Thread starter Thread starter Peter
  • Start date Start date
So you're saying that the DateModified and TimeModified fields are being
updated (why are you storing them in separate fields, btw? You should have a
single field and populate it using the Now function), but that Operator
isn't? That makes no sense.

For debugging purposes, try the following:

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo BeforeUpdate_Err

MsgBox "Before: Operator " & Me.Operator & vbCrLf & _
"(" & Me.DateModified & " " & Me.TimeModified & ")" & vbCrLf & _
"fOSUserName = " & fOSUserName()

' Set bound controls to system date and time and current user name.
Me.DateModified = Date
Me.TimeModified = Time()
Me.Operator = fOSUserName()

MsgBox "After: Operator " & Me.Operator & vbCrLf & _
"(" & Me.DateModified & " " & Me.TimeModified & ")"

BeforeUpdate_End:
Exit Sub

BeforeUpdate_Err:
MsgBox Err.Description, vbCritical & vbOKOnly, _
"Error Number " & Err.Number & " Occurred"
Resume BeforeUpdate_End

End Sub
 
When i replace my code with yours i receive two small popups after exiting
the record..i did some edits

1. Before: Operator (29/05/2009 17:51:48) fOSUername =
2. After: Operator (29/05/2009 17:54:16)
 
When i replace my code with yours i receive two small popups after exiting
the record..i did some edits

1. Before: Operator (29/05/2009 17:51:48) fOSUername =
2. After: Operator (29/05/2009 17:54:16)
 
...and the reson for the seperate Time Date fieled is this idea that i want to
caclulate the elapsed tome between time created and time modified in the
future..just an experiment...
 
...and the reson for the seperate Time Date fieled is this idea that i want to
caclulate the elapsed tome between time created and time modified in the
future..just an experiment...
 
When i replace my code with yours i receive two small popups after
exiting the record..i did some edits

1. Before: Operator (29/05/2009 17:51:48) fOSUername =
2. After: Operator (29/05/2009 17:54:16)

Your function is not working.
 
When i replace my code with yours i receive two small popups after
exiting the record..i did some edits

1. Before: Operator (29/05/2009 17:51:48) fOSUername =
2. After: Operator (29/05/2009 17:54:16)

Your function is not working.
 
I have not changed the name of the Module other then the default,
Module1...the function part of the module was automatically named
fOSUsername...and if i use the controll source in a unbound textfield =
fOSUername ()..it does return the correct value...is there any other way to
bypass this problem...the update event functions well for date and time...so
i know when the record was last edited..but not by whome..
 
I have not changed the name of the Module other then the default,
Module1...the function part of the module was automatically named
fOSUsername...and if i use the controll source in a unbound textfield =
fOSUername ()..it does return the correct value...is there any other way to
bypass this problem...the update event functions well for date and time...so
i know when the record was last edited..but not by whome..
 
Like David says, there's a problem with your fOSUserName function. Are you
sure that it still works if you set the ControlSource of a text box to
=fOSUserName?
 
Like David says, there's a problem with your fOSUserName function. Are you
sure that it still works if you set the ControlSource of a text box to
=fOSUserName?
 
Yes Douglas. Unbound textbox with controll source =fOSUserName() works just
fine..perhaps i should just set an invisible textbox with =fOSUserName() and
refer to that the following way:

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo BeforeUpdate_Err

' Set bound controls to system date and time and current user name.
Me.DateModified = Date
Me.TimeModified = Time()
Me.Username = Forms!Spider_reports.UserName

The date
BeforeUpdate_End:
Exit Sub
BeforeUpdate_Err:
MsgBox Err.Description, vbCritical & vbOKOnly, _
"Error Number " & Err.Number & " Occurred"
Resume BeforeUpdate_End
End Sub


I will deffently use the DateDiff in order to be able to calculate the time
spent on a specific record...Thanks..well..step by step...day by day..:-)
 
Yes Douglas. Unbound textbox with controll source =fOSUserName() works just
fine..perhaps i should just set an invisible textbox with =fOSUserName() and
refer to that the following way:

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo BeforeUpdate_Err

' Set bound controls to system date and time and current user name.
Me.DateModified = Date
Me.TimeModified = Time()
Me.Username = Forms!Spider_reports.UserName

The date
BeforeUpdate_End:
Exit Sub
BeforeUpdate_Err:
MsgBox Err.Description, vbCritical & vbOKOnly, _
"Error Number " & Err.Number & " Occurred"
Resume BeforeUpdate_End
End Sub


I will deffently use the DateDiff in order to be able to calculate the time
spent on a specific record...Thanks..well..step by step...day by day..:-)
 
Shouldn't need to be administrator, and I'm unaware of any interactions
between Access and advapi32.dll
 
I have not changed the name of the Module other then the default,
Module1...the function part of the module was automatically named
fOSUsername...and if i use the controll source in a unbound
textfield = fOSUername ()..it does return the correct value...is
there any other way to bypass this problem...the update event
functions well for date and time...so i know when the record was
last edited..but not by whome..

Well, for one, in what you posted:

you misspelled the name of your function. I don't know where you
copied that from, but it ought to throw an error in code, unless you
don't have Option Explicit in the module where you're calling it.

For what it's worth, I use a wrapper function around the function
that makes API call to get the user logon because I think it's
senseless to ask Windows the user logon every time you need to
record it -- it certainly can't change within a single Access
session. So I use the function posted after my signature.

For the function you're using, you'd replace "fGetUserName" with
your function name, "fOSUername". What that code does is it calls it
once and stores it in the Static variable. As long as the Static
variable remains live, it will return the variable and not bother to
ask the OS again.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/

Public Function UserLogon() As String
Static strUserLogon As String

If Len(strUserLogon) = 0 Then
strUserLogon = fGetUserName()
End If
UserLogon = strUserLogon
End Function
 
nbound textbox with controll source =fOSUserName() works just
fine..perhaps i should just set an invisible textbox with
=fOSUserName() and refer to that the following way:

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo BeforeUpdate_Err

' Set bound controls to system date and time and current user
name. Me.DateModified = Date
Me.TimeModified = Time()
Me.Username = Forms!Spider_reports.UserName

There is absolutely no reason why this shouldn't work:

Me.Username = fOSUserName()

If the function works in a control, then it should work there.
 
Hi Douglas..just for your information i solved this issue the following
way...and also included the Now()..only one controll..and also the Datediff
function..thanks for your patiance..the database is up and running well..you
are a good teacher.

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo BeforeUpdate_Err

' Set bound controls to system date and time and current user name.
Me.DateModified = Now()
Me.ModifiedBy = Forms![Username Form].[Operator]

BeforeUpdate_End:
Exit Sub
BeforeUpdate_Err:
MsgBox Err.Description, vbCritical & vbOKOnly, _
"Error Number " & Err.Number & " Occurred"
Resume BeforeUpdate_End
End Sub
 
Back
Top