By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,847 Members | 3,068 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,847 IT Pros & Developers. It's quick & easy.

generate list of log-ins

P: n/a
Thanks in advance! I have an un-secured database that I can see which
computer name is logged-on but not the user. I have an error module
that can get the user name. It writes to an error file.

What I'd like to do is to have an invisible error generated that would
post to this log, but do nothing else. Any ideas?

My error log works like this:

Call LogErr
'this calls my module named: modErrorLog:

Option Compare Database
Option Explicit

Public Sub LogErr(ByVal strEvent As String, ByVal strForm As String, _
ByVal bolShowMsg As Boolean)

Dim cnn As New ADODB.Connection
Dim rec As New ADODB.Recordset
Dim strSQL As String
Dim strUser As String
Dim strPC As String
Dim lngNum As Long

Dim objAPI As New clsAPI

With objAPI
strPC = .ComputerName
strUser = .UserName
End With

Set cnn = CurrentProject.Connection
cnn.CursorLocation = adUseClient
strSQL = "SELECT * FROM tblErrors"

rec.Open strSQL, cnn, adOpenKeyset, adLockOptimistic

Debug.Print rec.Supports(adAddNew)

With rec
.AddNew
.Fields("UserName").Value = strUser
.Fields("ComputerName").Value = strPC
.Update
End With

rec.Close
cnn.Close
Set cnn = Nothing
Set objAPI = Nothing

End Sub

Apr 17 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
do you have to generate an error? why not just call the procedure from the
Open event of the first form that opens (switchboard? main menu?) when the
db opens?

hth
"Parasyke" <kr************@yahoo.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
Thanks in advance! I have an un-secured database that I can see which
computer name is logged-on but not the user. I have an error module
that can get the user name. It writes to an error file.

What I'd like to do is to have an invisible error generated that would
post to this log, but do nothing else. Any ideas?

My error log works like this:

Call LogErr
'this calls my module named: modErrorLog:

Option Compare Database
Option Explicit

Public Sub LogErr(ByVal strEvent As String, ByVal strForm As String, _
ByVal bolShowMsg As Boolean)

Dim cnn As New ADODB.Connection
Dim rec As New ADODB.Recordset
Dim strSQL As String
Dim strUser As String
Dim strPC As String
Dim lngNum As Long

Dim objAPI As New clsAPI

With objAPI
strPC = .ComputerName
strUser = .UserName
End With

Set cnn = CurrentProject.Connection
cnn.CursorLocation = adUseClient
strSQL = "SELECT * FROM tblErrors"

rec.Open strSQL, cnn, adOpenKeyset, adLockOptimistic

Debug.Print rec.Supports(adAddNew)

With rec
.AddNew
.Fields("UserName").Value = strUser
.Fields("ComputerName").Value = strPC
.Update
End With

rec.Close
cnn.Close
Set cnn = Nothing
Set objAPI = Nothing

End Sub

Apr 17 '06 #2

P: n/a
Upon trying that:

Private Sub Form_Open(Cancel As Integer)
Call ErrorLog
End Sub

I get a compile error "Ambiguous Name Detected"

Apr 17 '06 #3

P: n/a
BTW: I wouldn't necessarily need to use this Error module if I could
find another way to write to a table the user name and the computer
name which my error handler does. If I use a module I got (which works
well) from http://www.mvps.org/access/modules/mdl0055.htm, all I get
tis the computer name and "unknown user".

Apr 17 '06 #4

P: n/a
well, the name of the procedure that you posted is "LogErr". have you tried
calling that, as

Private Sub Form_Open(Cancel As Integer)
LogErr
End Sub

i imagine you'll get a compile error requiring that you supply values to the
procedure's arguments (strEvent, strForm, and bolShowMsg), but since i
didn't see any of those variables used in the procedure, it shouldn't really
matter what values you pass.

btw, i've never heard of "calling" an entire module, only a procedure in a
module - though of course i haven't heard of everything, by a long shot. at
any rate, suggest you try the above OpenForm code, and see if it works for
you.

hth
"Parasyke" <kr************@yahoo.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Upon trying that:

Private Sub Form_Open(Cancel As Integer)
Call ErrorLog
End Sub

I get a compile error "Ambiguous Name Detected"

Apr 18 '06 #5

P: n/a
Add the code below to a module, and call the function called fOSUserName()
from the on open event of your form, and that will give you the user name
logged onto the PC.

-----
Option Compare Database
Option Explicit

'******************** Code Start **************************
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Sub sapiSleep Lib "kernel32" _
Alias "Sleep" _
(ByVal dwMilliseconds As Long)

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function
-------------------------------

Regards
SB.

"Parasyke" <kr************@yahoo.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
BTW: I wouldn't necessarily need to use this Error module if I could
find another way to write to a table the user name and the computer
name which my error handler does. If I use a module I got (which works
well) from http://www.mvps.org/access/modules/mdl0055.htm, all I get
tis the computer name and "unknown user".

Apr 18 '06 #6

P: n/a
In my module the following is displaying in red:

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

The compile message seems to be expecting a "String Constant".

Apr 18 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.