Microsoft Access & VB

Tarrant64

Diamond Member
Sep 20, 2004
3,203
0
76
I am wondering if anyone could help me out a little bit with something I think may be possible. I work on a few different databases here at my job, Access databases. Here and there I run into adding things with VB to tie things together with forms, etc.

Everyone in awhile though some glitches occur, or somethign changes, or things start missing. I am wondering if it's possible to add in some VB code or something that will run in the background with Access running. Something that will send to a text file saying, "x user is accessing y database/form/report/etc." More like a log if anything.

It doesn't matter if it just logs it when the database is started, as long as it tells me user, time.

I was just thinking it may even be more useful if I had code tied to a form so when it opens it sends information to a log file(in the background of course so as not to interfere with users).


Sum:
Need code(VB) to monitor activity of MS Access database.
Any suggestions or possible example codes I could be linked to?
Open to suggestions. Thanks!
 

theknight571

Platinum Member
Mar 23, 2001
2,896
2
81

The Access Web is a good resource for code examples etc.

The following code can be found Here

The code uses the Windows User Name...so it appears.

If this isn't exactly what you're looking for let me know, or perhaps It'll point you in the right direction. :)

Note: The periods are to aid in the spacing of the code in the form... in the actual code they are spaces. :)


'******************** Code Start **************************
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
... "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) 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 = vbNullString
... End If
End Function
'******************** Code End **************************


Private Sub Form_Open(Cancel As Integer)
...Open "LOGFILE.TXT" For Append As #1
...Write #1, fOSUserName() & " - Logged in on " & Date & " at " & Time
...Close #1
End Sub

 

Tarrant64

Diamond Member
Sep 20, 2004
3,203
0
76
Thanks, I will check this out. I'm not sure if it's what I need yet or not, but I know someone who should be able to help me out with the code and to figure it out when applying it to what Im trying to do.