Understandable documentation regarding Access DBA security

D

David W. Fenton

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
 
D

David W. Fenton

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.
 
P

Peter

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top