Tracking Log In and Log Out times of Users

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to track the log in and log out tie of users. I would like to store
this information in a table and be able to refer back to it, if needed. I
was also wondering if the log could track what forms, queries or table each
indivudal opened while online.
 
On my website (www.rogersaccesslibrary.com), are two small Access database
samples called "AuditTrail.mdb" and "AuditTrail2.mdb" which do something
similar to this. These sample track the actual changes to table records,
not which forms were visited, but you should be able to modify it for your
needs.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
It will take a little work, but you can do it. First, you will need to be
able to capture the userid of the logged on user. Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

You're app will need a form that is opened when assess opens. You identify
that form from the menu bar Tools, Startup and put the name of the form in
Display Form/Page:

This form should always be open. You can make it invisible, but it is the
easiest way to handle closing the application without having to put code in
every form's close event.

You will need a function in a standard module that can be accessed from any
form or report that will write an entry to an audit log table.

Then in the Load event of each form and report, call the function and pass
it the information you want captured in your audit log.

Tracking tables and queries is not really necessary. If the app is
structured so that users cannot get directly to these objects (that is the
way it should be), you will know what data the user is working with from the
forms and reports they open.

And when the use closes the app, our famous invisible statup form's Close
event should capture that fact and update the audit table.
 
Klatuu said:
It will take a little work, but you can do it. First, you will need to be
able to capture the userid of the logged on user. Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules
You're app will need a form that is opened when assess opens. You identify
that form from the menu bar Tools, Startup and put the name of the form in
Display Form/Page:

I have a start-up form that opens when the database opens.
This form should always be open. You can make it invisible, but it is the
easiest way to handle closing the application without having to put code in
every form's close event.

My startup form is always open and is the only way to navigate within the
database
You will need a function in a standard module that can be accessed from any
form or report that will write an entry to an audit log table.

I have a audit log tabel, however what fields should I put in this table.
What would this function look like. I'm new to module and I'm trying to
learn how to write code and how this works.
Then in the Load event of each form and report, call the function and pass
it the information you want captured in your audit log.

Are you talking about the function you mentioned above? I'm assuming that
what you mean is on each form on my start-up screen I should write code to
the on load of the properties of the form that will refer to the function
created above and this will write to the audit log
 
I downloaded your sample database and this is exactly what I'm looking for.
I'm just not sure how to convert it over to my database. I imported your
audit table structure over and placed a copy of your qryViewAuditTrail query
in my database. I then exported your AuditFunctions and UserComputer Modules
over to my database. I'm assuming that these two modules do not have any
code that is database specific and there did not appear that there was
anything in the code of these two modules that I needed to change and that
all I needed to do was copy them over Now for the confusing part. I'm
assuming that now I have to write code in the property of each form in the
BeforeInsert and On Delete simlar to yours for each form that I use? I'm new
to writing code so bear with me. My first form is based on a query and only
have a few fields. I change the txttablename to txtQueryName (because this
form is based on a query) and may it equal to my query. I then took the
address section of code and changed it to the date read field in my query and
deleted everything else in the writeauditUpdate of your code. The date read
field is the only thing that can be changed in this query. I then left
eveything else the same.
 
See answers below, I hope this is useful.

Dan said:
I have copy this code and placed it in my modules


I have a start-up form that opens when the database opens.


My startup form is always open and is the only way to navigate within the
database


I have a audit log tabel, however what fields should I put in this table.
What would this function look like. I'm new to module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out). As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log and the
other would be using a recordset.
To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function
Are you talking about the function you mentioned above? I'm assuming that
what you mean is on each form on my start-up screen I should write code to
the on load of the properties of the form that will refer to the function
created above and this will write to the audit log

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can also be used in a
Macro, except you will have to hard code the Macro's name in place of
Me.Name. Now, you could also track any other activity you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close event to know the
object was closed.
Now let's say you want to record that a user exported data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")
 
see below

Klatuu said:
See answers below, I hope this is useful.



What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId, TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log

I also set up an append query, but I'm not sure how to refer back to it on
the load to add a record.

and the
other would be using a recordset.

Im not sure what a recordset is or how to use it
To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to call it? Do I need
to go to Expression, Macro or Code builder or do I just type in
AuditLogger("Logged In") in the box next to on load.
Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code above.
 
We have too many nested answers and it is getting hard to follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you don't need to
worry abount an append query. The code I sent uses the recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that method, although
it is not the only way to do it. With your form or report open in design
view, open the properties dialog and select the Events tab. Click in the text
box for the Load event. Click the command button with the 3 dots when it
appears. select code builder. Now put the call to the function in the event
procedure.

Dan said:
see below

Klatuu said:
See answers below, I hope this is useful.



What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId, TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log
c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it
To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to call it? Do I need
to go to Expression, Macro or Code builder or do I just type in
AuditLogger("Logged In") in the box next to on load.
Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code above.

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can also be used in a
Macro, except you will have to hard code the Macro's name in place of
Me.Name. Now, you could also track any other activity you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close event to know the
object was closed.
Now let's say you want to record that a user exported data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")
 
I sorry this is what I dont understand how to put the call to the function in
the event
procedure. I have never worked with modules before and this is all new to
me. I'm assuming that this a command line that goes like "Call AuditLogger"
then "end sub"


Klatuu said:
We have too many nested answers and it is getting hard to follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you don't need to
worry abount an append query. The code I sent uses the recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that method, although
it is not the only way to do it. With your form or report open in design
view, open the properties dialog and select the Events tab. Click in the text
box for the Load event. Click the command button with the 3 dots when it
appears. select code builder. Now put the call to the function in the event
procedure.

Dan said:
see below

Klatuu said:
See answers below, I hope this is useful.

:



:

It will take a little work, but you can do it. First, you will need to be
able to capture the userid of the logged on user. Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules

You're app will need a form that is opened when assess opens. You identify
that form from the menu bar Tools, Startup and put the name of the form in
Display Form/Page:

I have a start-up form that opens when the database opens.

This form should always be open. You can make it invisible, but it is the
easiest way to handle closing the application without having to put code in
every form's close event.

My startup form is always open and is the only way to navigate within the
database

You will need a function in a standard module that can be accessed from any
form or report that will write an entry to an audit log table.

I have a audit log tabel, however what fields should I put in this table.
What would this function look like. I'm new to module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId, TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log
c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it
To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to call it? Do I need
to go to Expression, Macro or Code builder or do I just type in
AuditLogger("Logged In") in the box next to on load.
Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code above.

Then in the Load event of each form and report, call the function and pass
it the information you want captured in your audit log.

Are you talking about the function you mentioned above? I'm assuming that
what you mean is on each form on my start-up screen I should write code to
the on load of the properties of the form that will refer to the function
created above and this will write to the audit log

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can also be used in a
Macro, except you will have to hard code the Macro's name in place of
Me.Name. Now, you could also track any other activity you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close event to know the
object was closed.
Now let's say you want to record that a user exported data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")


Tracking tables and queries is not really necessary. If the app is
structured so that users cannot get directly to these objects (that is the
way it should be), you will know what data the user is working with from the
forms and reports they open.

And when the use closes the app, our famous invisible statup form's Close
event should capture that fact and update the audit table.

:

I need to track the log in and log out tie of users. I would like to store
this information in a table and be able to refer back to it, if needed. I
was also wondering if the log could track what forms, queries or table each
indivudal opened while online.
 
You don't need to use Call. Call is for Subs, this is a function. Subs and
Functions are very similar, but there are some differences.

To repeat the instructions I posted earlier:
With your form or report open in design view, open the properties dialog and
select the Events tab. Click in the text box for the Load event. Click the
command button with the 3 dots when it appears. select code builder.

Once you have selected Code Builder, the VBA editor will show with the sub
declaration already done. This is where you put the call to the function,
which is:

AuditLogger(Me.Name)

Dan said:
I sorry this is what I dont understand how to put the call to the function in
the event
procedure. I have never worked with modules before and this is all new to
me. I'm assuming that this a command line that goes like "Call AuditLogger"
then "end sub"


Klatuu said:
We have too many nested answers and it is getting hard to follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you don't need to
worry abount an append query. The code I sent uses the recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that method, although
it is not the only way to do it. With your form or report open in design
view, open the properties dialog and select the Events tab. Click in the text
box for the Load event. Click the command button with the 3 dots when it
appears. select code builder. Now put the call to the function in the event
procedure.

Dan said:
see below

:

See answers below, I hope this is useful.

:



:

It will take a little work, but you can do it. First, you will need to be
able to capture the userid of the logged on user. Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules

You're app will need a form that is opened when assess opens. You identify
that form from the menu bar Tools, Startup and put the name of the form in
Display Form/Page:

I have a start-up form that opens when the database opens.

This form should always be open. You can make it invisible, but it is the
easiest way to handle closing the application without having to put code in
every form's close event.

My startup form is always open and is the only way to navigate within the
database

You will need a function in a standard module that can be accessed from any
form or report that will write an entry to an audit log table.

I have a audit log tabel, however what fields should I put in this table.
What would this function look like. I'm new to module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId, TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log
c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it

To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to call it? Do I need
to go to Expression, Macro or Code builder or do I just type in
AuditLogger("Logged In") in the box next to on load.

Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code above.



Then in the Load event of each form and report, call the function and pass
it the information you want captured in your audit log.

Are you talking about the function you mentioned above? I'm assuming that
what you mean is on each form on my start-up screen I should write code to
the on load of the properties of the form that will refer to the function
created above and this will write to the audit log

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can also be used in a
Macro, except you will have to hard code the Macro's name in place of
Me.Name. Now, you could also track any other activity you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close event to know the
object was closed.
Now let's say you want to record that a user exported data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")


Tracking tables and queries is not really necessary. If the app is
structured so that users cannot get directly to these objects (that is the
way it should be), you will know what data the user is working with from the
forms and reports they open.

And when the use closes the app, our famous invisible statup form's Close
event should capture that fact and update the audit table.

:

I need to track the log in and log out tie of users. I would like to store
this information in a table and be able to refer back to it, if needed. I
was also wondering if the log could track what forms, queries or table each
indivudal opened while online.
 
Sorry but I'm just learning how to use modules.
On my startup form, (that opens every time the database is open, but is
visible) I went to design and clicked on upper left box of the design form
and click on properties for the form. I then went to the load event and
clicked on the 3 dots and chose code builder. When it the code builder comes
up I have "form" in the left box and "Load" in the right dropdown box with
the following in the lower pane

Private Sub Form_Load()

End Sub

I then put AuditLogger("Logged In") as follows

Private Sub Form_Load()
AuditLogger("Logged In")
End Sub

I also did the same for my Closed Event except I put AuditLogger('Logged Out")

Then on the form that everyone accesses for this database I did the same
thing. I open it in designe view clicked on the box in the upper left
corner and then went to properties for the form then to Load event and did
the same as above but used

AuditLogger(me.Name)

However I keep getting an error message that says that AuditLogger is not a
module. I'm I doing this right. I have a icon in my Modules for AuditLogger
with the code you had given me before. Thanks for the help, I'm just
learning so I'm sorry for the repeted questions.

Klatuu said:
You don't need to use Call. Call is for Subs, this is a function. Subs and
Functions are very similar, but there are some differences.

To repeat the instructions I posted earlier:
With your form or report open in design view, open the properties dialog and
select the Events tab. Click in the text box for the Load event. Click the
command button with the 3 dots when it appears. select code builder.

Once you have selected Code Builder, the VBA editor will show with the sub
declaration already done. This is where you put the call to the function,
which is:

AuditLogger(Me.Name)

Dan said:
I sorry this is what I dont understand how to put the call to the function in
the event
procedure. I have never worked with modules before and this is all new to
me. I'm assuming that this a command line that goes like "Call AuditLogger"
then "end sub"


Klatuu said:
We have too many nested answers and it is getting hard to follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you don't need to
worry abount an append query. The code I sent uses the recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that method, although
it is not the only way to do it. With your form or report open in design
view, open the properties dialog and select the Events tab. Click in the text
box for the Load event. Click the command button with the 3 dots when it
appears. select code builder. Now put the call to the function in the event
procedure.

:

see below

:

See answers below, I hope this is useful.

:



:

It will take a little work, but you can do it. First, you will need to be
able to capture the userid of the logged on user. Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules

You're app will need a form that is opened when assess opens. You identify
that form from the menu bar Tools, Startup and put the name of the form in
Display Form/Page:

I have a start-up form that opens when the database opens.

This form should always be open. You can make it invisible, but it is the
easiest way to handle closing the application without having to put code in
every form's close event.

My startup form is always open and is the only way to navigate within the
database

You will need a function in a standard module that can be accessed from any
form or report that will write an entry to an audit log table.

I have a audit log tabel, however what fields should I put in this table.
What would this function look like. I'm new to module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId, TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log

c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it

To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to call it? Do I need
to go to Expression, Macro or Code builder or do I just type in
AuditLogger("Logged In") in the box next to on load.

Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code above.



Then in the Load event of each form and report, call the function and pass
it the information you want captured in your audit log.

Are you talking about the function you mentioned above? I'm assuming that
what you mean is on each form on my start-up screen I should write code to
the on load of the properties of the form that will refer to the function
created above and this will write to the audit log

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can also be used in a
Macro, except you will have to hard code the Macro's name in place of
Me.Name. Now, you could also track any other activity you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close event to know the
object was closed.
Now let's say you want to record that a user exported data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")


Tracking tables and queries is not really necessary. If the app is
structured so that users cannot get directly to these objects (that is the
way it should be), you will know what data the user is working with from the
forms and reports they open.

And when the use closes the app, our famous invisible statup form's Close
event should capture that fact and update the audit table.

:

I need to track the log in and log out tie of users. I would like to store
this information in a table and be able to refer back to it, if needed. I
was also wondering if the log could track what forms, queries or table each
indivudal opened while online.
 
AuditLogger is a Sub, not a module. Modules conain Subs and Functions.
There are 3 types of modules.
A Form module is an object attached to a form object that contains code for
that form. It loads with the form.
A Report module is the same, except it is specific to that report.
A Standard module is not associated with any specific form or report, but is
a collection of Subs and Functions visible to any object. This is where you
put code you want to use throughout the application.

Now, there is one important point. A module cannot have a Sub or Function
in it that has the same name as the module. For example, you nave a Function
name AuditLogger; therefore, you can't name the module AuditLogger. It will
confuse Access.

Dan said:
Sorry but I'm just learning how to use modules.
On my startup form, (that opens every time the database is open, but is
visible) I went to design and clicked on upper left box of the design form
and click on properties for the form. I then went to the load event and
clicked on the 3 dots and chose code builder. When it the code builder comes
up I have "form" in the left box and "Load" in the right dropdown box with
the following in the lower pane

Private Sub Form_Load()

End Sub

I then put AuditLogger("Logged In") as follows

Private Sub Form_Load()
AuditLogger("Logged In")
End Sub

I also did the same for my Closed Event except I put AuditLogger('Logged Out")

Then on the form that everyone accesses for this database I did the same
thing. I open it in designe view clicked on the box in the upper left
corner and then went to properties for the form then to Load event and did
the same as above but used

AuditLogger(me.Name)

However I keep getting an error message that says that AuditLogger is not a
module. I'm I doing this right. I have a icon in my Modules for AuditLogger
with the code you had given me before. Thanks for the help, I'm just
learning so I'm sorry for the repeted questions.

Klatuu said:
You don't need to use Call. Call is for Subs, this is a function. Subs and
Functions are very similar, but there are some differences.

To repeat the instructions I posted earlier:
With your form or report open in design view, open the properties dialog and
select the Events tab. Click in the text box for the Load event. Click the
command button with the 3 dots when it appears. select code builder.

Once you have selected Code Builder, the VBA editor will show with the sub
declaration already done. This is where you put the call to the function,
which is:

AuditLogger(Me.Name)

Dan said:
I sorry this is what I dont understand how to put the call to the function in
the event
procedure. I have never worked with modules before and this is all new to
me. I'm assuming that this a command line that goes like "Call AuditLogger"
then "end sub"


:

We have too many nested answers and it is getting hard to follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you don't need to
worry abount an append query. The code I sent uses the recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that method, although
it is not the only way to do it. With your form or report open in design
view, open the properties dialog and select the Events tab. Click in the text
box for the Load event. Click the command button with the 3 dots when it
appears. select code builder. Now put the call to the function in the event
procedure.

:

see below

:

See answers below, I hope this is useful.

:



:

It will take a little work, but you can do it. First, you will need to be
able to capture the userid of the logged on user. Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules

You're app will need a form that is opened when assess opens. You identify
that form from the menu bar Tools, Startup and put the name of the form in
Display Form/Page:

I have a start-up form that opens when the database opens.

This form should always be open. You can make it invisible, but it is the
easiest way to handle closing the application without having to put code in
every form's close event.

My startup form is always open and is the only way to navigate within the
database

You will need a function in a standard module that can be accessed from any
form or report that will write an entry to an audit log table.

I have a audit log tabel, however what fields should I put in this table.
What would this function look like. I'm new to module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId, TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log

c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it

To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to call it? Do I need
to go to Expression, Macro or Code builder or do I just type in
AuditLogger("Logged In") in the box next to on load.

Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code above.



Then in the Load event of each form and report, call the function and pass
it the information you want captured in your audit log.

Are you talking about the function you mentioned above? I'm assuming that
what you mean is on each form on my start-up screen I should write code to
the on load of the properties of the form that will refer to the function
created above and this will write to the audit log

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can also be used in a
Macro, except you will have to hard code the Macro's name in place of
Me.Name. Now, you could also track any other activity you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close event to know the
object was closed.
Now let's say you want to record that a user exported data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")


Tracking tables and queries is not really necessary. If the app is
structured so that users cannot get directly to these objects (that is the
way it should be), you will know what data the user is working with from the
forms and reports they open.

And when the use closes the app, our famous invisible statup form's Close
event should capture that fact and update the audit table.

:

I need to track the log in and log out tie of users. I would like to store
this information in a table and be able to refer back to it, if needed. I
was also wondering if the log could track what forms, queries or table each
indivudal opened while online.
 
I made the change and rename my Fucnciton "Logger" and my Module
"AuditLogger". Now I'm getting an error when I run my forms that say it
can't find my table "AuditLog". Then it goes to the debuger and hightlights
Set rst = CurrentDb.OpenRecordset("AuditLog") in the code you gave me for the
auditlogger module which is listed below. Even if I use tblAuditLog as you
did, which I assume is the name you gave the table you created, I get the
same message. I'm assuming that because I did not use tbl to distinquish my
table in its name I do not need to use the tbl in the code or is tlb part of
the code?
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

Klatuu said:
AuditLogger is a Sub, not a module. Modules conain Subs and Functions.
There are 3 types of modules.
A Form module is an object attached to a form object that contains code for
that form. It loads with the form.
A Report module is the same, except it is specific to that report.
A Standard module is not associated with any specific form or report, but is
a collection of Subs and Functions visible to any object. This is where you
put code you want to use throughout the application.

Now, there is one important point. A module cannot have a Sub or Function
in it that has the same name as the module. For example, you nave a Function
name AuditLogger; therefore, you can't name the module AuditLogger. It will
confuse Access.

Dan said:
Sorry but I'm just learning how to use modules.
On my startup form, (that opens every time the database is open, but is
visible) I went to design and clicked on upper left box of the design form
and click on properties for the form. I then went to the load event and
clicked on the 3 dots and chose code builder. When it the code builder comes
up I have "form" in the left box and "Load" in the right dropdown box with
the following in the lower pane

Private Sub Form_Load()

End Sub

I then put AuditLogger("Logged In") as follows

Private Sub Form_Load()
AuditLogger("Logged In")
End Sub

I also did the same for my Closed Event except I put AuditLogger('Logged Out")

Then on the form that everyone accesses for this database I did the same
thing. I open it in designe view clicked on the box in the upper left
corner and then went to properties for the form then to Load event and did
the same as above but used

AuditLogger(me.Name)

However I keep getting an error message that says that AuditLogger is not a
module. I'm I doing this right. I have a icon in my Modules for AuditLogger
with the code you had given me before. Thanks for the help, I'm just
learning so I'm sorry for the repeted questions.

Klatuu said:
You don't need to use Call. Call is for Subs, this is a function. Subs and
Functions are very similar, but there are some differences.

To repeat the instructions I posted earlier:
With your form or report open in design view, open the properties dialog and
select the Events tab. Click in the text box for the Load event. Click the
command button with the 3 dots when it appears. select code builder.

Once you have selected Code Builder, the VBA editor will show with the sub
declaration already done. This is where you put the call to the function,
which is:

AuditLogger(Me.Name)

:

I sorry this is what I dont understand how to put the call to the function in
the event
procedure. I have never worked with modules before and this is all new to
me. I'm assuming that this a command line that goes like "Call AuditLogger"
then "end sub"


:

We have too many nested answers and it is getting hard to follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you don't need to
worry abount an append query. The code I sent uses the recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that method, although
it is not the only way to do it. With your form or report open in design
view, open the properties dialog and select the Events tab. Click in the text
box for the Load event. Click the command button with the 3 dots when it
appears. select code builder. Now put the call to the function in the event
procedure.

:

see below

:

See answers below, I hope this is useful.

:



:

It will take a little work, but you can do it. First, you will need to be
able to capture the userid of the logged on user. Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules

You're app will need a form that is opened when assess opens. You identify
that form from the menu bar Tools, Startup and put the name of the form in
Display Form/Page:

I have a start-up form that opens when the database opens.

This form should always be open. You can make it invisible, but it is the
easiest way to handle closing the application without having to put code in
every form's close event.

My startup form is always open and is the only way to navigate within the
database

You will need a function in a standard module that can be accessed from any
form or report that will write an entry to an audit log table.

I have a audit log tabel, however what fields should I put in this table.
What would this function look like. I'm new to module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId, TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log

c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it

To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to call it? Do I need
to go to Expression, Macro or Code builder or do I just type in
AuditLogger("Logged In") in the box next to on load.

Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code above.



Then in the Load event of each form and report, call the function and pass
it the information you want captured in your audit log.

Are you talking about the function you mentioned above? I'm assuming that
what you mean is on each form on my start-up screen I should write code to
the on load of the properties of the form that will refer to the function
created above and this will write to the audit log

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can also be used in a
Macro, except you will have to hard code the Macro's name in place of
Me.Name. Now, you could also track any other activity you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close event to know the
object was closed.
Now let's say you want to record that a user exported data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")


Tracking tables and queries is not really necessary. If the app is
structured so that users cannot get directly to these objects (that is the
way it should be), you will know what data the user is working with from the
forms and reports they open.

And when the use closes the app, our famous invisible statup form's Close
event should capture that fact and update the audit table.

:

I need to track the log in and log out tie of users. I would like to store
this information in a table and be able to refer back to it, if needed. I
was also wondering if the log could track what forms, queries or table each
indivudal opened while online.
 
It needs to be whatever the name of your table is.

Dan said:
I made the change and rename my Fucnciton "Logger" and my Module
"AuditLogger". Now I'm getting an error when I run my forms that say it
can't find my table "AuditLog". Then it goes to the debuger and hightlights
Set rst = CurrentDb.OpenRecordset("AuditLog") in the code you gave me for the
auditlogger module which is listed below. Even if I use tblAuditLog as you
did, which I assume is the name you gave the table you created, I get the
same message. I'm assuming that because I did not use tbl to distinquish my
table in its name I do not need to use the tbl in the code or is tlb part of
the code?
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

Klatuu said:
AuditLogger is a Sub, not a module. Modules conain Subs and Functions.
There are 3 types of modules.
A Form module is an object attached to a form object that contains code for
that form. It loads with the form.
A Report module is the same, except it is specific to that report.
A Standard module is not associated with any specific form or report, but is
a collection of Subs and Functions visible to any object. This is where you
put code you want to use throughout the application.

Now, there is one important point. A module cannot have a Sub or Function
in it that has the same name as the module. For example, you nave a Function
name AuditLogger; therefore, you can't name the module AuditLogger. It will
confuse Access.

Dan said:
Sorry but I'm just learning how to use modules.
On my startup form, (that opens every time the database is open, but is
visible) I went to design and clicked on upper left box of the design form
and click on properties for the form. I then went to the load event and
clicked on the 3 dots and chose code builder. When it the code builder comes
up I have "form" in the left box and "Load" in the right dropdown box with
the following in the lower pane

Private Sub Form_Load()

End Sub

I then put AuditLogger("Logged In") as follows

Private Sub Form_Load()
AuditLogger("Logged In")
End Sub

I also did the same for my Closed Event except I put AuditLogger('Logged Out")

Then on the form that everyone accesses for this database I did the same
thing. I open it in designe view clicked on the box in the upper left
corner and then went to properties for the form then to Load event and did
the same as above but used

AuditLogger(me.Name)

However I keep getting an error message that says that AuditLogger is not a
module. I'm I doing this right. I have a icon in my Modules for AuditLogger
with the code you had given me before. Thanks for the help, I'm just
learning so I'm sorry for the repeted questions.

:

You don't need to use Call. Call is for Subs, this is a function. Subs and
Functions are very similar, but there are some differences.

To repeat the instructions I posted earlier:
With your form or report open in design view, open the properties dialog and
select the Events tab. Click in the text box for the Load event. Click the
command button with the 3 dots when it appears. select code builder.

Once you have selected Code Builder, the VBA editor will show with the sub
declaration already done. This is where you put the call to the function,
which is:

AuditLogger(Me.Name)

:

I sorry this is what I dont understand how to put the call to the function in
the event
procedure. I have never worked with modules before and this is all new to
me. I'm assuming that this a command line that goes like "Call AuditLogger"
then "end sub"


:

We have too many nested answers and it is getting hard to follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you don't need to
worry abount an append query. The code I sent uses the recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that method, although
it is not the only way to do it. With your form or report open in design
view, open the properties dialog and select the Events tab. Click in the text
box for the Load event. Click the command button with the 3 dots when it
appears. select code builder. Now put the call to the function in the event
procedure.

:

see below

:

See answers below, I hope this is useful.

:



:

It will take a little work, but you can do it. First, you will need to be
able to capture the userid of the logged on user. Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules

You're app will need a form that is opened when assess opens. You identify
that form from the menu bar Tools, Startup and put the name of the form in
Display Form/Page:

I have a start-up form that opens when the database opens.

This form should always be open. You can make it invisible, but it is the
easiest way to handle closing the application without having to put code in
every form's close event.

My startup form is always open and is the only way to navigate within the
database

You will need a function in a standard module that can be accessed from any
form or report that will write an entry to an audit log table.

I have a audit log tabel, however what fields should I put in this table.
What would this function look like. I'm new to module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId, TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log

c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it

To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to call it? Do I need
to go to Expression, Macro or Code builder or do I just type in
AuditLogger("Logged In") in the box next to on load.

Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code above.



Then in the Load event of each form and report, call the function and pass
it the information you want captured in your audit log.

Are you talking about the function you mentioned above? I'm assuming that
what you mean is on each form on my start-up screen I should write code to
the on load of the properties of the form that will refer to the function
created above and this will write to the audit log

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can also be used in a
Macro, except you will have to hard code the Macro's name in place of
Me.Name. Now, you could also track any other activity you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close event to know the
object was closed.
Now let's say you want to record that a user exported data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")


Tracking tables and queries is not really necessary. If the app is
structured so that users cannot get directly to these objects (that is the
way it should be), you will know what data the user is working with from the
forms and reports they open.

And when the use closes the app, our famous invisible statup form's Close
event should capture that fact and update the audit table.

:

I need to track the log in and log out tie of users. I would like to store
this information in a table and be able to refer back to it, if needed. I
was also wondering if the log could track what forms, queries or table each
indivudal opened while online.
 
also when I go into the form it give me an error message that says Run Time
Error '13': Type mismatch and then highlights Set rst =
CurrentDb.OpenRecordset("AuditLog")

Dan said:
I made the change and rename my Fucnciton "Logger" and my Module
"AuditLogger". Now I'm getting an error when I run my forms that say it
can't find my table "AuditLog". Then it goes to the debuger and hightlights
Set rst = CurrentDb.OpenRecordset("AuditLog") in the code you gave me for the
auditlogger module which is listed below. Even if I use tblAuditLog as you
did, which I assume is the name you gave the table you created, I get the
same message. I'm assuming that because I did not use tbl to distinquish my
table in its name I do not need to use the tbl in the code or is tlb part of
the code?
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

Klatuu said:
AuditLogger is a Sub, not a module. Modules conain Subs and Functions.
There are 3 types of modules.
A Form module is an object attached to a form object that contains code for
that form. It loads with the form.
A Report module is the same, except it is specific to that report.
A Standard module is not associated with any specific form or report, but is
a collection of Subs and Functions visible to any object. This is where you
put code you want to use throughout the application.

Now, there is one important point. A module cannot have a Sub or Function
in it that has the same name as the module. For example, you nave a Function
name AuditLogger; therefore, you can't name the module AuditLogger. It will
confuse Access.

Dan said:
Sorry but I'm just learning how to use modules.
On my startup form, (that opens every time the database is open, but is
visible) I went to design and clicked on upper left box of the design form
and click on properties for the form. I then went to the load event and
clicked on the 3 dots and chose code builder. When it the code builder comes
up I have "form" in the left box and "Load" in the right dropdown box with
the following in the lower pane

Private Sub Form_Load()

End Sub

I then put AuditLogger("Logged In") as follows

Private Sub Form_Load()
AuditLogger("Logged In")
End Sub

I also did the same for my Closed Event except I put AuditLogger('Logged Out")

Then on the form that everyone accesses for this database I did the same
thing. I open it in designe view clicked on the box in the upper left
corner and then went to properties for the form then to Load event and did
the same as above but used

AuditLogger(me.Name)

However I keep getting an error message that says that AuditLogger is not a
module. I'm I doing this right. I have a icon in my Modules for AuditLogger
with the code you had given me before. Thanks for the help, I'm just
learning so I'm sorry for the repeted questions.

:

You don't need to use Call. Call is for Subs, this is a function. Subs and
Functions are very similar, but there are some differences.

To repeat the instructions I posted earlier:
With your form or report open in design view, open the properties dialog and
select the Events tab. Click in the text box for the Load event. Click the
command button with the 3 dots when it appears. select code builder.

Once you have selected Code Builder, the VBA editor will show with the sub
declaration already done. This is where you put the call to the function,
which is:

AuditLogger(Me.Name)

:

I sorry this is what I dont understand how to put the call to the function in
the event
procedure. I have never worked with modules before and this is all new to
me. I'm assuming that this a command line that goes like "Call AuditLogger"
then "end sub"


:

We have too many nested answers and it is getting hard to follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you don't need to
worry abount an append query. The code I sent uses the recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that method, although
it is not the only way to do it. With your form or report open in design
view, open the properties dialog and select the Events tab. Click in the text
box for the Load event. Click the command button with the 3 dots when it
appears. select code builder. Now put the call to the function in the event
procedure.

:

see below

:

See answers below, I hope this is useful.

:



:

It will take a little work, but you can do it. First, you will need to be
able to capture the userid of the logged on user. Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules

You're app will need a form that is opened when assess opens. You identify
that form from the menu bar Tools, Startup and put the name of the form in
Display Form/Page:

I have a start-up form that opens when the database opens.

This form should always be open. You can make it invisible, but it is the
easiest way to handle closing the application without having to put code in
every form's close event.

My startup form is always open and is the only way to navigate within the
database

You will need a function in a standard module that can be accessed from any
form or report that will write an entry to an audit log table.

I have a audit log tabel, however what fields should I put in this table.
What would this function look like. I'm new to module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId, TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log

c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it

To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to call it? Do I need
to go to Expression, Macro or Code builder or do I just type in
AuditLogger("Logged In") in the box next to on load.

Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code above.



Then in the Load event of each form and report, call the function and pass
it the information you want captured in your audit log.

Are you talking about the function you mentioned above? I'm assuming that
what you mean is on each form on my start-up screen I should write code to
the on load of the properties of the form that will refer to the function
created above and this will write to the audit log

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can also be used in a
Macro, except you will have to hard code the Macro's name in place of
Me.Name. Now, you could also track any other activity you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close event to know the
object was closed.
Now let's say you want to record that a user exported data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")


Tracking tables and queries is not really necessary. If the app is
structured so that users cannot get directly to these objects (that is the
way it should be), you will know what data the user is working with from the
forms and reports they open.

And when the use closes the app, our famous invisible statup form's Close
event should capture that fact and update the audit table.

:

I need to track the log in and log out tie of users. I would like to store
this information in a table and be able to refer back to it, if needed. I
was also wondering if the log could track what forms, queries or table each
indivudal opened while online.
 
This one I don't understand. I see your dim as
Dim rst As Recordset.

If you have both DAO and ADO references set, this might be the problem. You
may need to specify
Dim rst As DAO.Recordset (or ADO if that is what you are using)

Dan said:
also when I go into the form it give me an error message that says Run Time
Error '13': Type mismatch and then highlights Set rst =
CurrentDb.OpenRecordset("AuditLog")

Dan said:
I made the change and rename my Fucnciton "Logger" and my Module
"AuditLogger". Now I'm getting an error when I run my forms that say it
can't find my table "AuditLog". Then it goes to the debuger and hightlights
Set rst = CurrentDb.OpenRecordset("AuditLog") in the code you gave me for the
auditlogger module which is listed below. Even if I use tblAuditLog as you
did, which I assume is the name you gave the table you created, I get the
same message. I'm assuming that because I did not use tbl to distinquish my
table in its name I do not need to use the tbl in the code or is tlb part of
the code?
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

Klatuu said:
AuditLogger is a Sub, not a module. Modules conain Subs and Functions.
There are 3 types of modules.
A Form module is an object attached to a form object that contains code for
that form. It loads with the form.
A Report module is the same, except it is specific to that report.
A Standard module is not associated with any specific form or report, but is
a collection of Subs and Functions visible to any object. This is where you
put code you want to use throughout the application.

Now, there is one important point. A module cannot have a Sub or Function
in it that has the same name as the module. For example, you nave a Function
name AuditLogger; therefore, you can't name the module AuditLogger. It will
confuse Access.

:

Sorry but I'm just learning how to use modules.
On my startup form, (that opens every time the database is open, but is
visible) I went to design and clicked on upper left box of the design form
and click on properties for the form. I then went to the load event and
clicked on the 3 dots and chose code builder. When it the code builder comes
up I have "form" in the left box and "Load" in the right dropdown box with
the following in the lower pane

Private Sub Form_Load()

End Sub

I then put AuditLogger("Logged In") as follows

Private Sub Form_Load()
AuditLogger("Logged In")
End Sub

I also did the same for my Closed Event except I put AuditLogger('Logged Out")

Then on the form that everyone accesses for this database I did the same
thing. I open it in designe view clicked on the box in the upper left
corner and then went to properties for the form then to Load event and did
the same as above but used

AuditLogger(me.Name)

However I keep getting an error message that says that AuditLogger is not a
module. I'm I doing this right. I have a icon in my Modules for AuditLogger
with the code you had given me before. Thanks for the help, I'm just
learning so I'm sorry for the repeted questions.

:

You don't need to use Call. Call is for Subs, this is a function. Subs and
Functions are very similar, but there are some differences.

To repeat the instructions I posted earlier:
With your form or report open in design view, open the properties dialog and
select the Events tab. Click in the text box for the Load event. Click the
command button with the 3 dots when it appears. select code builder.

Once you have selected Code Builder, the VBA editor will show with the sub
declaration already done. This is where you put the call to the function,
which is:

AuditLogger(Me.Name)

:

I sorry this is what I dont understand how to put the call to the function in
the event
procedure. I have never worked with modules before and this is all new to
me. I'm assuming that this a command line that goes like "Call AuditLogger"
then "end sub"


:

We have too many nested answers and it is getting hard to follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you don't need to
worry abount an append query. The code I sent uses the recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that method, although
it is not the only way to do it. With your form or report open in design
view, open the properties dialog and select the Events tab. Click in the text
box for the Load event. Click the command button with the 3 dots when it
appears. select code builder. Now put the call to the function in the event
procedure.

:

see below

:

See answers below, I hope this is useful.

:



:

It will take a little work, but you can do it. First, you will need to be
able to capture the userid of the logged on user. Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules

You're app will need a form that is opened when assess opens. You identify
that form from the menu bar Tools, Startup and put the name of the form in
Display Form/Page:

I have a start-up form that opens when the database opens.

This form should always be open. You can make it invisible, but it is the
easiest way to handle closing the application without having to put code in
every form's close event.

My startup form is always open and is the only way to navigate within the
database

You will need a function in a standard module that can be accessed from any
form or report that will write an entry to an audit log table.

I have a audit log tabel, however what fields should I put in this table.
What would this function look like. I'm new to module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId, TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log

c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it

To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to call it? Do I need
to go to Expression, Macro or Code builder or do I just type in
AuditLogger("Logged In") in the box next to on load.

Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code above.



Then in the Load event of each form and report, call the function and pass
it the information you want captured in your audit log.

Are you talking about the function you mentioned above? I'm assuming that
what you mean is on each form on my start-up screen I should write code to
the on load of the properties of the form that will refer to the function
created above and this will write to the audit log

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can also be used in a
Macro, except you will have to hard code the Macro's name in place of
Me.Name. Now, you could also track any other activity you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close event to know the
object was closed.
Now let's say you want to record that a user exported data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")


Tracking tables and queries is not really necessary. If the app is
structured so that users cannot get directly to these objects (that is the
way it should be), you will know what data the user is working with from the
forms and reports they open.

And when the use closes the app, our famous invisible statup form's Close
event should capture that fact and update the audit table.

:

I need to track the log in and log out tie of users. I would like to store
this information in a table and be able to refer back to it, if needed. I
was also wondering if the log could track what forms, queries or table each
indivudal opened while online.
 
Does it matter that I'm on a server. the IT people have restrictions set up
This one I don't understand. I see your dim as
Dim rst As Recordset.

If you have both DAO and ADO references set, this might be the problem. You
may need to specify
Dim rst As DAO.Recordset (or ADO if that is what you are using)

Dan said:
also when I go into the form it give me an error message that says Run Time
Error '13': Type mismatch and then highlights Set rst =
CurrentDb.OpenRecordset("AuditLog")

Dan said:
I made the change and rename my Fucnciton "Logger" and my Module
"AuditLogger". Now I'm getting an error when I run my forms that say it
can't find my table "AuditLog". Then it goes to the debuger and hightlights
Set rst = CurrentDb.OpenRecordset("AuditLog") in the code you gave me for the
auditlogger module which is listed below. Even if I use tblAuditLog as you
did, which I assume is the name you gave the table you created, I get the
same message. I'm assuming that because I did not use tbl to distinquish my
table in its name I do not need to use the tbl in the code or is tlb part of
the code?

Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function


:

AuditLogger is a Sub, not a module. Modules conain Subs and Functions.
There are 3 types of modules.
A Form module is an object attached to a form object that contains code for
that form. It loads with the form.
A Report module is the same, except it is specific to that report.
A Standard module is not associated with any specific form or report, but is
a collection of Subs and Functions visible to any object. This is where you
put code you want to use throughout the application.

Now, there is one important point. A module cannot have a Sub or Function
in it that has the same name as the module. For example, you nave a Function
name AuditLogger; therefore, you can't name the module AuditLogger. It will
confuse Access.

:

Sorry but I'm just learning how to use modules.
On my startup form, (that opens every time the database is open, but is
visible) I went to design and clicked on upper left box of the design form
and click on properties for the form. I then went to the load event and
clicked on the 3 dots and chose code builder. When it the code builder comes
up I have "form" in the left box and "Load" in the right dropdown box with
the following in the lower pane

Private Sub Form_Load()

End Sub

I then put AuditLogger("Logged In") as follows

Private Sub Form_Load()
AuditLogger("Logged In")
End Sub

I also did the same for my Closed Event except I put AuditLogger('Logged Out")

Then on the form that everyone accesses for this database I did the same
thing. I open it in designe view clicked on the box in the upper left
corner and then went to properties for the form then to Load event and did
the same as above but used

AuditLogger(me.Name)

However I keep getting an error message that says that AuditLogger is not a
module. I'm I doing this right. I have a icon in my Modules for AuditLogger
with the code you had given me before. Thanks for the help, I'm just
learning so I'm sorry for the repeted questions.

:

You don't need to use Call. Call is for Subs, this is a function. Subs and
Functions are very similar, but there are some differences.

To repeat the instructions I posted earlier:
With your form or report open in design view, open the properties dialog and
select the Events tab. Click in the text box for the Load event. Click the
command button with the 3 dots when it appears. select code builder.

Once you have selected Code Builder, the VBA editor will show with the sub
declaration already done. This is where you put the call to the function,
which is:

AuditLogger(Me.Name)

:

I sorry this is what I dont understand how to put the call to the function in
the event
procedure. I have never worked with modules before and this is all new to
me. I'm assuming that this a command line that goes like "Call AuditLogger"
then "end sub"


:

We have too many nested answers and it is getting hard to follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you don't need to
worry abount an append query. The code I sent uses the recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that method, although
it is not the only way to do it. With your form or report open in design
view, open the properties dialog and select the Events tab. Click in the text
box for the Load event. Click the command button with the 3 dots when it
appears. select code builder. Now put the call to the function in the event
procedure.

:

see below

:

See answers below, I hope this is useful.

:



:

It will take a little work, but you can do it. First, you will need to be
able to capture the userid of the logged on user. Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules

You're app will need a form that is opened when assess opens. You identify
that form from the menu bar Tools, Startup and put the name of the form in
Display Form/Page:

I have a start-up form that opens when the database opens.

This form should always be open. You can make it invisible, but it is the
easiest way to handle closing the application without having to put code in
every form's close event.

My startup form is always open and is the only way to navigate within the
database

You will need a function in a standard module that can be accessed from any
form or report that will write an entry to an audit log table.

I have a audit log tabel, however what fields should I put in this table.
What would this function look like. I'm new to module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId, TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log

c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it

To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to call it? Do I need
to go to Expression, Macro or Code builder or do I just type in
AuditLogger("Logged In") in the box next to on load.

Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code above.



Then in the Load event of each form and report, call the function and pass
it the information you want captured in your audit log.

Are you talking about the function you mentioned above? I'm assuming that
what you mean is on each form on my start-up screen I should write code to
the on load of the properties of the form that will refer to the function
created above and this will write to the audit log

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can also be used in a
Macro, except you will have to hard code the Macro's name in place of
Me.Name. Now, you could also track any other activity you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close event to know the
object was closed.
Now let's say you want to record that a user exported data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")


Tracking tables and queries is not really necessary. If the app is
structured so that users cannot get directly to these objects (that is the
way it should be), you will know what data the user is working with from the
forms and reports they open.

And when the use closes the app, our famous invisible statup form's Close
event should capture that fact and update the audit table.

:

I need to track the log in and log out tie of users. I would like to store
this information in a table and be able to refer back to it, if needed. I
was also wondering if the log could track what forms, queries or table each
indivudal opened while online.
 
I tried both Dim rst as DAO.Recordset and ADO and still came up with errors.
Could it be that my database is on a server?

Klatuu said:
This one I don't understand. I see your dim as
Dim rst As Recordset.

If you have both DAO and ADO references set, this might be the problem. You
may need to specify
Dim rst As DAO.Recordset (or ADO if that is what you are using)

Dan said:
also when I go into the form it give me an error message that says Run Time
Error '13': Type mismatch and then highlights Set rst =
CurrentDb.OpenRecordset("AuditLog")

Dan said:
I made the change and rename my Fucnciton "Logger" and my Module
"AuditLogger". Now I'm getting an error when I run my forms that say it
can't find my table "AuditLog". Then it goes to the debuger and hightlights
Set rst = CurrentDb.OpenRecordset("AuditLog") in the code you gave me for the
auditlogger module which is listed below. Even if I use tblAuditLog as you
did, which I assume is the name you gave the table you created, I get the
same message. I'm assuming that because I did not use tbl to distinquish my
table in its name I do not need to use the tbl in the code or is tlb part of
the code?

Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function


:

AuditLogger is a Sub, not a module. Modules conain Subs and Functions.
There are 3 types of modules.
A Form module is an object attached to a form object that contains code for
that form. It loads with the form.
A Report module is the same, except it is specific to that report.
A Standard module is not associated with any specific form or report, but is
a collection of Subs and Functions visible to any object. This is where you
put code you want to use throughout the application.

Now, there is one important point. A module cannot have a Sub or Function
in it that has the same name as the module. For example, you nave a Function
name AuditLogger; therefore, you can't name the module AuditLogger. It will
confuse Access.

:

Sorry but I'm just learning how to use modules.
On my startup form, (that opens every time the database is open, but is
visible) I went to design and clicked on upper left box of the design form
and click on properties for the form. I then went to the load event and
clicked on the 3 dots and chose code builder. When it the code builder comes
up I have "form" in the left box and "Load" in the right dropdown box with
the following in the lower pane

Private Sub Form_Load()

End Sub

I then put AuditLogger("Logged In") as follows

Private Sub Form_Load()
AuditLogger("Logged In")
End Sub

I also did the same for my Closed Event except I put AuditLogger('Logged Out")

Then on the form that everyone accesses for this database I did the same
thing. I open it in designe view clicked on the box in the upper left
corner and then went to properties for the form then to Load event and did
the same as above but used

AuditLogger(me.Name)

However I keep getting an error message that says that AuditLogger is not a
module. I'm I doing this right. I have a icon in my Modules for AuditLogger
with the code you had given me before. Thanks for the help, I'm just
learning so I'm sorry for the repeted questions.

:

You don't need to use Call. Call is for Subs, this is a function. Subs and
Functions are very similar, but there are some differences.

To repeat the instructions I posted earlier:
With your form or report open in design view, open the properties dialog and
select the Events tab. Click in the text box for the Load event. Click the
command button with the 3 dots when it appears. select code builder.

Once you have selected Code Builder, the VBA editor will show with the sub
declaration already done. This is where you put the call to the function,
which is:

AuditLogger(Me.Name)

:

I sorry this is what I dont understand how to put the call to the function in
the event
procedure. I have never worked with modules before and this is all new to
me. I'm assuming that this a command line that goes like "Call AuditLogger"
then "end sub"


:

We have too many nested answers and it is getting hard to follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you don't need to
worry abount an append query. The code I sent uses the recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that method, although
it is not the only way to do it. With your form or report open in design
view, open the properties dialog and select the Events tab. Click in the text
box for the Load event. Click the command button with the 3 dots when it
appears. select code builder. Now put the call to the function in the event
procedure.

:

see below

:

See answers below, I hope this is useful.

:



:

It will take a little work, but you can do it. First, you will need to be
able to capture the userid of the logged on user. Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules

You're app will need a form that is opened when assess opens. You identify
that form from the menu bar Tools, Startup and put the name of the form in
Display Form/Page:

I have a start-up form that opens when the database opens.

This form should always be open. You can make it invisible, but it is the
easiest way to handle closing the application without having to put code in
every form's close event.

My startup form is always open and is the only way to navigate within the
database

You will need a function in a standard module that can be accessed from any
form or report that will write an entry to an audit log table.

I have a audit log tabel, however what fields should I put in this table.
What would this function look like. I'm new to module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You probably want UserId,
TimeStamp, and Object Accessed. (that would be the form or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId, TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to the audit log

c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it

To call the function, you would put something like this in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to call it? Do I need
to go to Expression, Macro or Code builder or do I just type in
AuditLogger("Logged In") in the box next to on load.

Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code above.



Then in the Load event of each form and report, call the function and pass
it the information you want captured in your audit log.

Are you talking about the function you mentioned above? I'm assuming that
what you mean is on each form on my start-up screen I should write code to
the on load of the properties of the form that will refer to the function
created above and this will write to the audit log

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can also be used in a
Macro, except you will have to hard code the Macro's name in place of
Me.Name. Now, you could also track any other activity you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close event to know the
object was closed.
Now let's say you want to record that a user exported data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")


Tracking tables and queries is not really necessary. If the app is
structured so that users cannot get directly to these objects (that is the
way it should be), you will know what data the user is working with from the
forms and reports they open.

And when the use closes the app, our famous invisible statup form's Close
event should capture that fact and update the audit table.

:

I need to track the log in and log out tie of users. I would like to store
this information in a table and be able to refer back to it, if needed. I
was also wondering if the log could track what forms, queries or table each
indivudal opened while online.
 
The fact that the database is on the server should be irrelevant. Regardless
of the location of the database, you're running Access on your workstation.

Your code is using DAO: the statement "Set rst =
CurrentDb.OpenRecordset("tblAuditLog")" proves that.

That means your declaration needs to be:

Dim rst As DAO.Recordset

If that statement generates an error, then I suspect you don't have a
reference set to DAO. With any code module open, select Tools | References
from the menu bar, scroll through the list of available references until you
find the one for Microsoft DAO 3.6 Object Library, and select it.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Dan said:
I tried both Dim rst as DAO.Recordset and ADO and still came up with
errors.
Could it be that my database is on a server?

Klatuu said:
This one I don't understand. I see your dim as
Dim rst As Recordset.

If you have both DAO and ADO references set, this might be the problem.
You
may need to specify
Dim rst As DAO.Recordset (or ADO if that is what you are using)

Dan said:
also when I go into the form it give me an error message that says Run
Time
Error '13': Type mismatch and then highlights Set rst =
CurrentDb.OpenRecordset("AuditLog")

:

I made the change and rename my Fucnciton "Logger" and my Module
"AuditLogger". Now I'm getting an error when I run my forms that say
it
can't find my table "AuditLog". Then it goes to the debuger and
hightlights
Set rst = CurrentDb.OpenRecordset("AuditLog") in the code you gave me
for the
auditlogger module which is listed below. Even if I use tblAuditLog
as you
did, which I assume is the name you gave the table you created, I get
the
same message. I'm assuming that because I did not use tbl to
distinquish my
table in its name I do not need to use the tbl in the code or is tlb
part of
the code?

Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function


:

AuditLogger is a Sub, not a module. Modules conain Subs and
Functions.
There are 3 types of modules.
A Form module is an object attached to a form object that contains
code for
that form. It loads with the form.
A Report module is the same, except it is specific to that report.
A Standard module is not associated with any specific form or
report, but is
a collection of Subs and Functions visible to any object. This is
where you
put code you want to use throughout the application.

Now, there is one important point. A module cannot have a Sub or
Function
in it that has the same name as the module. For example, you nave
a Function
name AuditLogger; therefore, you can't name the module AuditLogger.
It will
confuse Access.

:

Sorry but I'm just learning how to use modules.
On my startup form, (that opens every time the database is open,
but is
visible) I went to design and clicked on upper left box of the
design form
and click on properties for the form. I then went to the load
event and
clicked on the 3 dots and chose code builder. When it the code
builder comes
up I have "form" in the left box and "Load" in the right dropdown
box with
the following in the lower pane

Private Sub Form_Load()

End Sub

I then put AuditLogger("Logged In") as follows

Private Sub Form_Load()
AuditLogger("Logged In")
End Sub

I also did the same for my Closed Event except I put
AuditLogger('Logged Out")

Then on the form that everyone accesses for this database I did
the same
thing. I open it in designe view clicked on the box in the
upper left
corner and then went to properties for the form then to Load
event and did
the same as above but used

AuditLogger(me.Name)

However I keep getting an error message that says that
AuditLogger is not a
module. I'm I doing this right. I have a icon in my Modules for
AuditLogger
with the code you had given me before. Thanks for the help, I'm
just
learning so I'm sorry for the repeted questions.

:

You don't need to use Call. Call is for Subs, this is a
function. Subs and
Functions are very similar, but there are some differences.

To repeat the instructions I posted earlier:
With your form or report open in design view, open the
properties dialog and
select the Events tab. Click in the text box for the Load
event. Click the
command button with the 3 dots when it appears. select code
builder.

Once you have selected Code Builder, the VBA editor will show
with the sub
declaration already done. This is where you put the call to
the function,
which is:

AuditLogger(Me.Name)

:

I sorry this is what I dont understand how to put the call to
the function in
the event
procedure. I have never worked with modules before and this
is all new to
me. I'm assuming that this a command line that goes like
"Call AuditLogger"
then "end sub"


:

We have too many nested answers and it is getting hard to
follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you
don't need to
worry abount an append query. The code I sent uses the
recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that
method, although
it is not the only way to do it. With your form or report
open in design
view, open the properties dialog and select the Events tab.
Click in the text
box for the Load event. Click the command button with the
3 dots when it
appears. select code builder. Now put the call to the
function in the event
procedure.

:

see below

:

See answers below, I hope this is useful.

:



:

It will take a little work, but you can do it.
First, you will need to be
able to capture the userid of the logged on user.
Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules

You're app will need a form that is opened when
assess opens. You identify
that form from the menu bar Tools, Startup and put
the name of the form in
Display Form/Page:

I have a start-up form that opens when the database
opens.

This form should always be open. You can make it
invisible, but it is the
easiest way to handle closing the application
without having to put code in
every form's close event.

My startup form is always open and is the only way to
navigate within the
database

You will need a function in a standard module that
can be accessed from any
form or report that will write an entry to an audit
log table.

I have a audit log tabel, however what fields should
I put in this table.
What would this function look like. I'm new to
module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You
probably want UserId,
TimeStamp, and Object Accessed. (that would be the form
or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId,
TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to
the audit log

c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it

To call the function, you would put something like this
in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to
call it? Do I need
to go to Expression, Macro or Code builder or do I just
type in
AuditLogger("Logged In") in the box next to on load.

Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function

I created a Module called AuditLogger with the code
above.



Then in the Load event of each form and report,
call the function and pass
it the information you want captured in your audit
log.

Are you talking about the function you mentioned
above? I'm assuming that
what you mean is on each form on my start-up screen I
should write code to
the on load of the properties of the form that will
refer to the function
created above and this will write to the audit log

In the Load event of every form and report
AuditLogger(Me.Name)
Will cause an entry to be written to the Log. It can
also be used in a
Macro, except you will have to hard code the Macro's
name in place of
Me.Name. Now, you could also track any other activity
you want by adding a
second argument to the function.
AuditLogger(Me.Name, "Open") - Call in the Load
event to know the object
was opened.
AuditLogger(Me.Name, "Close") - Call in the Close
event to know the
object was closed.
Now let's say you want to record that a user exported
data to Excel. You
could make calls in your VBA code to record that:
DoCmd.TransferSpreadsheet....
AuditLogger("qselSomeData", "Exported")


Tracking tables and queries is not really
necessary. If the app is
structured so that users cannot get directly to
these objects (that is the
way it should be), you will know what data the user
is working with from the
forms and reports they open.

And when the use closes the app, our famous
invisible statup form's Close
event should capture that fact and update the audit
table.

:

I need to track the log in and log out tie of
users. I would like to store
this information in a table and be able to refer
back to it, if needed. I
was also wondering if the log could track what
forms, queries or table each
indivudal opened while online.
 
I changed my code as seen below:

Option Compare Database
Public Function logger(strObject As String)
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("AuditLog")
With rst
.AddNew
![UserId] = GetCurrentUserName
![TimeStamp] = Now()
![ObjectAccessed] = strObject
![Computer] = GetComputerName
.Update
End With
Set rst = Nothing
End Function

Now when I open my form I get a Complie error: User-definded type not
defined with Public Function logger (strObject as String) hightlited in
yellow and rst as DAO.Recordset hightlighted in blue
Douglas J. Steele said:
The fact that the database is on the server should be irrelevant. Regardless
of the location of the database, you're running Access on your workstation.

Your code is using DAO: the statement "Set rst =
CurrentDb.OpenRecordset("tblAuditLog")" proves that.

That means your declaration needs to be:

Dim rst As DAO.Recordset

If that statement generates an error, then I suspect you don't have a
reference set to DAO. With any code module open, select Tools | References
from the menu bar, scroll through the list of available references until you
find the one for Microsoft DAO 3.6 Object Library, and select it.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Dan said:
I tried both Dim rst as DAO.Recordset and ADO and still came up with
errors.
Could it be that my database is on a server?

Klatuu said:
This one I don't understand. I see your dim as
Dim rst As Recordset.

If you have both DAO and ADO references set, this might be the problem.
You
may need to specify
Dim rst As DAO.Recordset (or ADO if that is what you are using)

:

also when I go into the form it give me an error message that says Run
Time
Error '13': Type mismatch and then highlights Set rst =
CurrentDb.OpenRecordset("AuditLog")

:

I made the change and rename my Fucnciton "Logger" and my Module
"AuditLogger". Now I'm getting an error when I run my forms that say
it
can't find my table "AuditLog". Then it goes to the debuger and
hightlights
Set rst = CurrentDb.OpenRecordset("AuditLog") in the code you gave me
for the
auditlogger module which is listed below. Even if I use tblAuditLog
as you
did, which I assume is the name you gave the table you created, I get
the
same message. I'm assuming that because I did not use tbl to
distinquish my
table in its name I do not need to use the tbl in the code or is tlb
part of
the code?

Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
.AddNew
![User] = Me.UserId
![TimeStamp] = Now()
![OjbectAccessed] = strObject
.Update
End Wtih
Set rst = Nothing
End Function


:

AuditLogger is a Sub, not a module. Modules conain Subs and
Functions.
There are 3 types of modules.
A Form module is an object attached to a form object that contains
code for
that form. It loads with the form.
A Report module is the same, except it is specific to that report.
A Standard module is not associated with any specific form or
report, but is
a collection of Subs and Functions visible to any object. This is
where you
put code you want to use throughout the application.

Now, there is one important point. A module cannot have a Sub or
Function
in it that has the same name as the module. For example, you nave
a Function
name AuditLogger; therefore, you can't name the module AuditLogger.
It will
confuse Access.

:

Sorry but I'm just learning how to use modules.
On my startup form, (that opens every time the database is open,
but is
visible) I went to design and clicked on upper left box of the
design form
and click on properties for the form. I then went to the load
event and
clicked on the 3 dots and chose code builder. When it the code
builder comes
up I have "form" in the left box and "Load" in the right dropdown
box with
the following in the lower pane

Private Sub Form_Load()

End Sub

I then put AuditLogger("Logged In") as follows

Private Sub Form_Load()
AuditLogger("Logged In")
End Sub

I also did the same for my Closed Event except I put
AuditLogger('Logged Out")

Then on the form that everyone accesses for this database I did
the same
thing. I open it in designe view clicked on the box in the
upper left
corner and then went to properties for the form then to Load
event and did
the same as above but used

AuditLogger(me.Name)

However I keep getting an error message that says that
AuditLogger is not a
module. I'm I doing this right. I have a icon in my Modules for
AuditLogger
with the code you had given me before. Thanks for the help, I'm
just
learning so I'm sorry for the repeted questions.

:

You don't need to use Call. Call is for Subs, this is a
function. Subs and
Functions are very similar, but there are some differences.

To repeat the instructions I posted earlier:
With your form or report open in design view, open the
properties dialog and
select the Events tab. Click in the text box for the Load
event. Click the
command button with the 3 dots when it appears. select code
builder.

Once you have selected Code Builder, the VBA editor will show
with the sub
declaration already done. This is where you put the call to
the function,
which is:

AuditLogger(Me.Name)

:

I sorry this is what I dont understand how to put the call to
the function in
the event
procedure. I have never worked with modules before and this
is all new to
me. I'm assuming that this a command line that goes like
"Call AuditLogger"
then "end sub"


:

We have too many nested answers and it is getting hard to
follow. I apologize
if I missed something.

If you copied the code I posted into a function, then you
don't need to
worry abount an append query. The code I sent uses the
recordset way of
doing it.

Since you are trying to learn to use VBA, we will use that
method, although
it is not the only way to do it. With your form or report
open in design
view, open the properties dialog and select the Events tab.
Click in the text
box for the Load event. Click the command button with the
3 dots when it
appears. select code builder. Now put the call to the
function in the event
procedure.

:

see below

:

See answers below, I hope this is useful.

:



:

It will take a little work, but you can do it.
First, you will need to be
able to capture the userid of the logged on user.
Here is a link to an API
routine that does that:
http://www.mvps.org/access/api/api0008.htm

I have copy this code and placed it in my modules

You're app will need a form that is opened when
assess opens. You identify
that form from the menu bar Tools, Startup and put
the name of the form in
Display Form/Page:

I have a start-up form that opens when the database
opens.

This form should always be open. You can make it
invisible, but it is the
easiest way to handle closing the application
without having to put code in
every form's close event.

My startup form is always open and is the only way to
navigate within the
database

You will need a function in a standard module that
can be accessed from any
form or report that will write an entry to an audit
log table.

I have a audit log tabel, however what fields should
I put in this table.
What would this function look like. I'm new to
module and I'm trying to
learn how to write code and how this works.

What fields you put in the table are up to you. You
probably want UserId,
TimeStamp, and Object Accessed. (that would be the form
or report opened, or
Logged In or Logged Out).

I set up my AuditLog with 4 fields, autoNumber, UserId,
TimeStamp and Object
Accessed


As to the code, it could be done a couple of ways.
One would be an append query that would add a row to
the audit log

c>
and the
other would be using a recordset.

Im not sure what a recordset is or how to use it

To call the function, you would put something like this
in the Load event of
each form or report:
AuditLogger(Me.Name)
and in the Load event of your main form
AuditLogger("Logged In")
and in the Close event of your main form
AuditLogger("Logged Out")

I'm not sure how to call the function. What do I do to
call it? Do I need
to go to Expression, Macro or Code builder or do I just
type in
AuditLogger("Logged In") in the box next to on load.

Now the function (which must be in a standard module)
Public Function AuditLogger(strObject as String)
Dim rst As Recordset

Set rst = CurrentDb.OpenRecordset("tblAuditLog")
With rst
 
Back
Top