Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / January 2006

Tip: Looking for answers? Try searching our database.

Calculated Field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NoviceIan - 30 Jan 2006 10:47 GMT
Hi,

We have a database which keeps track of staff training.  We have three
tables staff, course and training.  The course tabvle stores details of the
individual courses and their compliancy periods.

Course

Course #
Course Name
Compliancy Period

Training

Attended #
Staff #
Date Completed
Compliant Until

The training table stores details of the staffs attendence or participation
in training.  The compliancy period is currently a long integer which is
measured in months.  

What I would like to do is create a automated field which will indicate
compliant or expired based on the date the course was attended and the
compliancy period of the course.

I do not know where to start.  Please could somebody help me.

Many thanks

Ian
Allen Browne - 30 Jan 2006 11:38 GMT
Create a query.
Add both tables.

Type this into a fresh column in the Field row:
   Expiry: DateAdd("m", [Compliancy Period], [DateCompleted])

Add whatever criteria you wish below this calculated field.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> We have a database which keeps track of staff training.  We have three
> tables staff, course and training.  The course tabvle stores details of
[quoted text clipped - 28 lines]
>
> Ian
NoviceIan - 30 Jan 2006 12:47 GMT
Thanks I tested your criteria and it works.  However i have two questions.

The first is that not all courses are compliancy based some are just one
off.  With the code you give me the fields displays Error if the course is
not compiancy based.  Is there any way to just leave the field blank if this
is the case?

The second is would I be able to specify this code in the table design in
order to basically replace the Compliant Until field?

Many thanks

Ian

> Create a query.
> Add both tables.
[quoted text clipped - 36 lines]
> >
> > Ian
Allen Browne - 30 Jan 2006 13:56 GMT
How do you determine that the course does not need repeating? Is the
[Compliancy Period] null?

If so, you could use an IIf() expression and test if the field is Null. I
recommend you now wrap the expression in CVDate() to help poor ol' JET 4
understand what's meant to be returned:
   Expiry: CVDate(IIf(Compliancy Period] Is Null, DateAdd("m", [Compliancy
Period], [DateCompleted]))

You could use an Update query (Update on Query menu, in query design), and
put the expression in the Update row under the field you want to update. But
I recommend that you do not do this, unless you have a need to be able to
modify individual cases so that a person gets an extended period or a
reduced period. If you will not be doing that (and I suspect that would be
unusual), then storing the calculated value breaks one of the most basic
rules of data normalization - don't store dependent values - and you are
creating a maintenance nightmare for yourself. Why not let Access do all the
hard work instead of taking that on yourself? You can use the query with the
calculated date in any context where you could use the table, and you never
have to worry about whether you have handled every possible situation where
the data could be changed to ensure your stored calculated values are
correct.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Thanks I tested your criteria and it works.  However i have two questions.
>
[quoted text clipped - 46 lines]
>> > compliant or expired based on the date the course was attended and the
>> > compliancy period of the course.
NoviceIan - 30 Jan 2006 14:48 GMT
Hi again,

I tried your amended code and it keeps stopping on the first Compliancy
Period stating: The expression contains invalid syntax.

I see your point about the calculated fields and I will gratefully take your
advice thanks very much.

Ian

> How do you determine that the course does not need repeating? Is the
> [Compliancy Period] null?
[quoted text clipped - 69 lines]
> >> > compliant or expired based on the date the course was attended and the
> >> > compliancy period of the course.
Allen Browne - 30 Jan 2006 15:42 GMT
Bracketing wasn't right. This is all one line:

   Expiry: CVDate(IIf(IsNull([Compliancy Period]), Null,
       DateAdd("m", [Compliancy Period], [DateCompleted])))

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Hi again,
>
[quoted text clipped - 97 lines]
>> >> > the
>> >> > compliancy period of the course.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.