Time Stamping

B

Bill

I have a form "Notes" which I use to write my notes relating to the record.
This is simply a form with a text (memo) field which allows me to add and add
and add.

Each time I "add" additional notes, I want to insert my initials and a
date/time stamp.

Can Create a macro which will do this for me? Maybe just the date/time
stamping and I will add my initials??

Thanks,
 
S

strive4peace

Hi Bill,

no need to worry about code for the time and date ...

add this field to the table where you store notes:

Field Name --> DateAdd
Data Type --> Date/time
DefaultValue --> =Now()

as for the intials ... what I like to do is define a database property
for whoever is using it and when I add or change a record, I get the
value to record who added or changed a record -- but I don't know how
good you are with code... my guess is, since you want to record initials
instead of a UserID that you are fairly new to Access...


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
B

Bill

Wow I'm that obvious! LOL.

Ok so you guessed it, I'm pretty new but learning. Allow me to give a great
explanation...

I have a table (datasheet) which contains many fields for a incident report
system. Then I have a form (IR_Main) which contains many tabed sub-forms all
built off the same table (datasheet). Once the user enters all information
they click a print button which puts everything out to a PDF. I can go into
the system and add my follow-up notes which then gets printed (Added) to the
PDF.

So, although I think I see where your going with adding the field to the
table, I want the date/time stamp to show in the form window and they get
passed to the PDF.

Example of the form I use:

Notes:

BY 07-03-08/1600hrs
Called TT and ck'd status

BY 07-02-08/1330hrs
Reviewed report and sent for correctins

I would love to press CTRL-? to insert this stamp into the form.

Thanks,

Bill
 
S

strive4peace

Hi Bill,

"I would love to press CTRL-? to insert this stamp into the form"

well you can... but the format is different*

1. press --> CTRL ;
(current date)
2. then press --> SPACEBAR
3. press CTRL-SHIFT-:
(current time)

"I have a table which contains many fields for a incident report system"

*a* table??? you should have several ... sounds like you need to
normalize (read Access Basics in my siggy)

"contains many fields" -- more than 30? That is, IMO a BIG table...

"many tabed sub-forms all built off the same table"

that will get you into trouble... each form/subform should be based on
one table (which yours are) -- but also, each table should only be used
by one form or subform (for changing data) at a time -- there are
exceptions to this, but, IMO, it should be a general rule-of-thumb

~~~~~~
*
"07-03-08/1600hrs"

if you have date and time stored in a field, you can get that format
this way:

format([fieldname],"mm-dd-yy/hhmm\h\r\s")

you can also put
mm-dd-yy/hhmm\h\r\s
into the Format property of a control or field

This is assuming that the data type of fieldname is Date/Time


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
B

Bill

Crystal,

This is great! Thank you. The CTRL ; and CTRL SHFT ; work perfect. Is
there away to create a macro for a single key stroke?

I will be reviewing your access basics for some tips. The table holds
something like 30+ fields (Colums). I did it this way as everything outputs
to a custom report in a very nice layout. Although my report barely fit
within the restrictions of the report lenght by access (22inches).

Not sure what you mean by "but also, each table should only be used
by one form or subform (for changing data) at a time". I think I'm doing
this, but not sure. The user completes information contained on the tab. The
tab is visible only when a check box is checked. For example is the user has
a general liability claim and checks that box tab 1-3, & 6 open. If the have
a work comp claim and check the box tab 1,2,5,6,&7 are revealed. Then when
complete all info is passed to the report for creating the PDF. I really
like the way it's working just trying to make a short cut for my follow up
notes.

Thanks,

Bill

strive4peace said:
Hi Bill,

"I would love to press CTRL-? to insert this stamp into the form"

well you can... but the format is different*

1. press --> CTRL ;
(current date)
2. then press --> SPACEBAR
3. press CTRL-SHIFT-:
(current time)

"I have a table which contains many fields for a incident report system"

*a* table??? you should have several ... sounds like you need to
normalize (read Access Basics in my siggy)

"contains many fields" -- more than 30? That is, IMO a BIG table...

"many tabed sub-forms all built off the same table"

that will get you into trouble... each form/subform should be based on
one table (which yours are) -- but also, each table should only be used
by one form or subform (for changing data) at a time -- there are
exceptions to this, but, IMO, it should be a general rule-of-thumb

~~~~~~
*
"07-03-08/1600hrs"

if you have date and time stored in a field, you can get that format
this way:

format([fieldname],"mm-dd-yy/hhmm\h\r\s")

you can also put
mm-dd-yy/hhmm\h\r\s
into the Format property of a control or field

This is assuming that the data type of fieldname is Date/Time


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*



Wow I'm that obvious! LOL.

Ok so you guessed it, I'm pretty new but learning. Allow me to give a great
explanation...

I have a table (datasheet) which contains many fields for a incident report
system. Then I have a form (IR_Main) which contains many tabed sub-forms all
built off the same table (datasheet). Once the user enters all information
they click a print button which puts everything out to a PDF. I can go into
the system and add my follow-up notes which then gets printed (Added) to the
PDF.

So, although I think I see where your going with adding the field to the
table, I want the date/time stamp to show in the form window and they get
passed to the PDF.

Example of the form I use:

Notes:

BY 07-03-08/1600hrs
Called TT and ck'd status

BY 07-02-08/1330hrs
Reviewed report and sent for correctins

I would love to press CTRL-? to insert this stamp into the form.

Thanks,

Bill
 
S

strive4peace

Hi Bill,

you are welcome :)

"Is there away to create a macro for a single key stroke?"

well, you can just make the Default Value --> =Now()

but, if you want a quick way to put it in, how about using a
Double-click event? here would be the [Event Procedure] code:

'~~~~~~~~~~~~~~~~
me.ActiveControl = Now()
'~~~~~~~~~~~~~~~~

"I think I'm doing this, but not sure. "

I said that because you said this, "which contains many tabed sub-forms
all built off the same table (datasheet). "

if the information is just on tabs and NOT subforms, then you have
nothing to worry about ... other than your table probably isn't
normalized ;)


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*



Crystal,

This is great! Thank you. The CTRL ; and CTRL SHFT ; work perfect. Is
there away to create a macro for a single key stroke?

I will be reviewing your access basics for some tips. The table holds
something like 30+ fields (Colums). I did it this way as everything outputs
to a custom report in a very nice layout. Although my report barely fit
within the restrictions of the report lenght by access (22inches).

Not sure what you mean by "but also, each table should only be used
by one form or subform (for changing data) at a time". I think I'm doing
this, but not sure. The user completes information contained on the tab. The
tab is visible only when a check box is checked. For example is the user has
a general liability claim and checks that box tab 1-3, & 6 open. If the have
a work comp claim and check the box tab 1,2,5,6,&7 are revealed. Then when
complete all info is passed to the report for creating the PDF. I really
like the way it's working just trying to make a short cut for my follow up
notes.

Thanks,

Bill

strive4peace said:
Hi Bill,

"I would love to press CTRL-? to insert this stamp into the form"

well you can... but the format is different*

1. press --> CTRL ;
(current date)
2. then press --> SPACEBAR
3. press CTRL-SHIFT-:
(current time)

"I have a table which contains many fields for a incident report system"

*a* table??? you should have several ... sounds like you need to
normalize (read Access Basics in my siggy)

"contains many fields" -- more than 30? That is, IMO a BIG table...

"many tabed sub-forms all built off the same table"

that will get you into trouble... each form/subform should be based on
one table (which yours are) -- but also, each table should only be used
by one form or subform (for changing data) at a time -- there are
exceptions to this, but, IMO, it should be a general rule-of-thumb

~~~~~~
*
"07-03-08/1600hrs"

if you have date and time stored in a field, you can get that format
this way:

format([fieldname],"mm-dd-yy/hhmm\h\r\s")

you can also put
mm-dd-yy/hhmm\h\r\s
into the Format property of a control or field

This is assuming that the data type of fieldname is Date/Time


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*



Wow I'm that obvious! LOL.

Ok so you guessed it, I'm pretty new but learning. Allow me to give a great
explanation...

I have a table (datasheet) which contains many fields for a incident report
system. Then I have a form (IR_Main) which contains many tabed sub-forms all
built off the same table (datasheet). Once the user enters all information
they click a print button which puts everything out to a PDF. I can go into
the system and add my follow-up notes which then gets printed (Added) to the
PDF.

So, although I think I see where your going with adding the field to the
table, I want the date/time stamp to show in the form window and they get
passed to the PDF.

Example of the form I use:

Notes:

BY 07-03-08/1600hrs
Called TT and ck'd status

BY 07-02-08/1330hrs
Reviewed report and sent for correctins

I would love to press CTRL-? to insert this stamp into the form.

Thanks,

Bill

:

Hi Bill,

no need to worry about code for the time and date ...

add this field to the table where you store notes:

Field Name --> DateAdd
Data Type --> Date/time
DefaultValue --> =Now()

as for the intials ... what I like to do is define a database property
for whoever is using it and when I add or change a record, I get the
value to record who added or changed a record -- but I don't know how
good you are with code... my guess is, since you want to record initials
instead of a UserID that you are fairly new to Access...


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*




Bill wrote:
I have a form "Notes" which I use to write my notes relating to the record.
This is simply a form with a text (memo) field which allows me to add and add
and add.

Each time I "add" additional notes, I want to insert my initials and a
date/time stamp.

Can Create a macro which will do this for me? Maybe just the date/time
stamping and I will add my initials??

Thanks,
 
J

John W. Vinson

I will be reviewing your access basics for some tips. The table holds
something like 30+ fields (Colums). I did it this way as everything outputs
to a custom report in a very nice layout. Although my report barely fit
within the restrictions of the report lenght by access (22inches).

I think Crystal will agree that you're on shaky ground here. Designing a table
structure to fit a final report is *a very bad idea* - it's all but certain to
give you a badly non-normalized design. You really should design your tables
based on the logical structure of the data (Entities related one to many to
other Entities, and so on); it may be a fair bit more work to construct the
desired report, but it will be vastly easier to design your data entry forms,
and all the *other* reports that you'll someday want. Designing to fit a
complex paper report will very likely lead to your painting yourself into a
corner!
 
S

strive4peace

thanks, John

"I think Crystal will agree that you're on shaky ground here"

yes, I agree!

Bill, while you might think that your duct tape and bailing wire (sorry
for that analogy, but as you learn more, you will see it is appropriate)
is holding up pretty well... give it time. A solid foundation for what
you are building (database) will save you countless headaches down the
road -- better to make it strong now (so it will still stand in a storm)

"Designing a table structure to fit a final report is *a very bad idea*"

absolutely! Tables cannot be defined by what you want out. Reports are
like paint on walls, like windows and skylights -- the building must be
strong for them to last.

"You really should design your tables based on the logical structure of
the data"

Tables define nouns and events. A noun is something you can visualize
(person, place, thing) -- I am sure that was hammered in when you went
to grammer school

Fields in each table are like adjectives that describe it.

Since I do not know exactly what you are tracking, I cannot give
examples but I'll take a guess

Incident: that is an event so that would be a table with some kind of
date, place, and other nouns.

what does an incident involve?

People? can you visualize a person? that is a table

do the people have contact information? an address maybe (houses or
buildings, hey that sounds like another "noun" since you can visualize
it... so, another table) ... one or more phone numbers? (each of those
numbers is attached to a phone -- duh! -- that is something you can
visualize and, yup you guessed it, should be described in another table)

did the incident happen somewhere? that is a Place (Location)

what happened in the event? Perhaps a table with a list of the types of
things that might happen that you can tie to ...

.... are you starting to "see" what you are tracking?

~~~ initially, you wanted to set up your notes to record date/time but
also who made it. Those people that are making notes are "people"
objects and should be in a "people" table. People have a type (most
things do) -- employee? friend? derelict? company?

oh you are probably thinking that a company is not a 'person' ... but it
is ... it has an address, email, phone, website -- just like a human.
In law, humans and companies are the same -- in database structure, they
are also the same. Each has a main name (last name for human, company
name for company). A human object has information like first name and
birth date that an artificial person (company) does not have; a company
has information that a human does not have: employees, products,
subsideraries, ... etc ... what is common between humans and companies,
in terms of data, is more than what is different.

The goal of any database is to sift what you are tracking into its
simplest terms ... and the simple way is almost always the hardest to see.

The most effective database structure will do just that; break
everything down into its simplest terms. If this intrigues you, read
Access Basics; eventually, you have to learn it -- so might as well be
sooner than later.

Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
D

dgodfrey

strive4peace said:
as for the intials ... what I like to do is define a database property
for whoever is using it and when I add or change a record, I get the
value to record who added or changed a record -- but I don't know how
good you are with code... my guess is, since you want to record initials
instead of a UserID that you are fairly new to Access...
I would LOVE to know how to do this, if you are feeling generous with some
sample code...would actually help me out with my project. I am new myself,
and I am terrible with code, but I am learning a ton from the people on this
forum.

Thanks,

Derek
 
S

strive4peace

Hi Derek,

sure, I will share it with you -- its a bit late (early?) for me right
now so I need to get some rest ... but I will put something together and
post it

meanwhile, read Access Basics in my siggy ...

"I am new myself, and I am terrible with code"

if you have a desire to learn and a logical mind, you WILL get better!


Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 
S

strive4peace

Hi Deek,

ready for some code?

when the main form of your database opens, you will need to make sure
that the database properties are set. If you create a database by
importing objects, the database properties do not come along, so it is
good to have a default value.

On the property sheet for the OPEN event of your main form:

=SetDefaultDatabaseProperties(true)

then, in a general module:

'~~~~~~~~~~~~~~~~~~~~~ SetDatabaseProperties
Public Function SetDefaultDatabaseProperties( _
Optional bSkipMsg As Boolean = True)

If Not IsPropertyDefined("DefaultUserID") Then
Set_Property "DefaultUserID", dbLong, -1, False
End If

If Not bSkipMsg Then MsgBox "Default Database Properties are set" _
, , "Done"

End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

two functions, IsPropertyDefined and Set_Property, are called -- and I
will give you that code later in this message

If you have a FE/BE database where each user has their own FE, then each
user can be assigned a long integer UserID. The tables will all have
the following tracking fields (I put them at the bottom of the structure
and also have code to add them automatically if they are missing):

datAdd, date/time, Description --> date/time record was added
datEdit, date/time, Description --> date/time record was edited
IDadd, long, Description --> User who added record
IDedit, long, Description --> User who last edited record

If the user id NOT defined, I use -1 for the userID. If you have a
table of Users with an Autonumber ID, chances are that the UserID will
be a positive value.

Use an Append query to add -1 as the UserID for a non-defined user once
other records are already in. You can also use zero (0) -- but I like
-1 since it is never there unless you specifically put it there.

~~~

so how do you add the tracking fields to the tables?

datAdd is easy ... define a Default Value
=Now()
for the field in the table design

Whenever you create a record, it will automatically be filled out with
the current date and time

~~~

the other tracking fields are updated on the form BeforeUpdate event
(and you should never put records into a table directly unless you are a
developer and you know what you are doing <smile>). Here is what you
put in the property sheet for the BeforeUpdate event of the FORM:

=FormBeforeUpdate([Form])

and here is code that goes in a general module:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FormBeforeUpdate
Public Function FormBeforeUpdate(pF As Form _
, Optional bSetParentToo As Boolean = False)

'7-8-08

On Error GoTo Proc_Err
If bSetParentToo Then
pF.Parent.datEdit = Now()
pF.Parent!IDedit _
= CurrentDb.Properties("DefaultUserID")
End If

If pF.NewRecord Then
'Date Added has a default value in the table definition
pF!IDadd _
= CurrentDb.Properties("DefaultUserID")
Exit Function
End If

pF!datEdit = Now()
pF!IDedit _
= CurrentDb.Properties("DefaultUserID")

Proc_Exit:
Exit Function

Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number _
& " FormBeforeUpdate"
Resume Proc_Exit
Resume
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

all records that are being changed are processed by the form
BeforeUpdate event -- that gives you a chance to validate required
fields and Cancel the update. It also gives you an opportunity to fill
tracking fields, such as is done here.

If you have record validation, you can call this procedure from code
behind the form using:

FormBeforeUpdate Me

If the record is a NewRecord, then only IDadd will be filled out

If the record is NOT a new record, meaning it is being modified, then
datEdit and IDedit will be filled out.
~~~

there is an optional parameter in the general code to also update the
main form if you are on a subform.

~~~~

what else you need in the general module are these procedures:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' this is a generic public function to see if
' a property is defined
'
'~~~~~~~~~~~~~~~~~~~~~ IsPropertyDefined
Public Function IsPropertyDefined( _
ByVal pPropName As String _
, Optional obj As Object _
) As Boolean

'Crystal (strive4peace2008 at yahoo.com)
'
'PARAMETERS
' Obj can be a database, a Tabledef, a Field...
' if it is missing, CurrentDb is used
'

On Error GoTo Proc_Err

IsPropertyDefined = False

Dim prp As dao.Property

If obj Is Nothing Then
Set obj = CurrentDb
End If

For Each prp In obj.Properties
If prp.Name = pPropName Then
IsPropertyDefined = True
GoTo Proc_Exit
End If
Next prp

Proc_Exit:
Set prp = Nothing
Exit Function


Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number _
& " ProcedureName"

Resume Proc_Exit

'if you want to single-step code to find error, CTRL-Break at MsgBox
'then set this to be the next statement
Resume


End Function

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' this is a generic public function to
' define a property
'
'~~~~~~~~~~~~~~~~~~~~~ Set_Property
Public Function Set_Property( _
pPropName As String _
, pPropType As Long _
, pValue As Variant _
, Optional pSayMessage As Boolean = True _
, Optional obj As Object _
) As Byte

'Crystal (strive4peace2008 at yahoo.com)

'set up Error Handler
On Error GoTo Proc_Err

If obj Is Nothing Then
Set obj = CurrentDb
End If

obj.Properties.Append obj.CreateProperty( _
pPropName, pPropType, pValue)

If pSayMessage Then
MsgBox pPropName & " is " _
& obj.Properties(pPropName) _
& " for " & obj.Name, , "Done"
End If

Proc_Exit:
Exit Function

Proc_Err:
'property is already defined
If Err.Number = 3367 Then
obj.Properties(pPropName) = pValue
Resume Proc_Exit
End If

MsgBox Err.Description, , _
"ERROR " & Err.Number _
& " Set_Property"

Resume Proc_Exit
Resume
End Function

'~~~~~~~~~~~~~~~~~~~~~~~~~

you will need to reference a DAO Library for this code to work.

Tools, References... from a module window

If a DAO library is not checked off at the top of the list, scroll to a
DAO Library (like Microsoft DAO 3.6 Library) and check it

---------- Compile ----------

Whenever you write or paste code, your should ALWAYS compile it before
you attempt to run it.

from the menu: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)

**********************************************************
*** How to Create a Standard (General) Module ***

1. from the database window, click on the Module tab
2. click on the NEW command button
3. type (or paste) the code in

once the code is in the module sheet, from the menu, do -->
Debug,Compile

if there are no syntax/reference errors, nothing will appear to happen
-- in this case, nothing happening is good <g>

Make sure to give the module a good name when you save it. You can have
several procedures (Subs and Functions) in a module, which gives you a
way to categorize them ... ie: basic procedures that would be useful in
any database; procedures that are specific to a particular database;
procedures for converting data; etc

~~~~~~~~~~~~~~~~~`

when you set up a FE for a specific user, assign the DefaultUserID
property for the database. You can press CTRL-G to Goto the debuG
(Immediate) window. Type the following statement:

Set_Property "DefaultUserID", dbLong, 215, True

and press ENTER

WHERE
Set_Property is the procedure name you are running
DefaultUserID is the name of the property you are setting
dbLong means it is stored as a Long Integer
215 is the value (Assuming this user has been assigned a UserID of 215)
True to give a confirmation message that the property is set



Warm Regards,
Crystal

remote programming and training

Access Basics
8-part free tutorial that covers essentials in Access
http://www.AccessMVP.com/strive4peace

*
:) have an awesome day :)
*
 

Ask a Question

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

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

Ask a Question

Top