Validation Rule

B

Billiam

I have a timesheet, with 2 fields, date/time format,medium date format,
called PayperiodFrom, and PayperiodTo. I also have a field called DateWorked,
and this is where the current date for data entry of the days hours is
placed...it is Date/Time Format, medium date.

I was hoping I could limit the choices available in DateWorked to those
which appear in the PayPeriod Range.

No matter what I try, I cannot seem to get the validation rule correct...
Is what I am after possible by using the validation rule property in the
DateWorked field? and would anyone have mercy and explain how?

You cannot know how much I would appreciate it, but I really would be
thankful for some help on this...
Billiam
 
B

Banana

I'd probably do this from a form rather from a table as it's much more
flexible in how you can express the logic. Look into using form's
beforeupdate event and setting Cancel=True if the validation fails.
 
B

Billiam

Hi,

Banana said:
I'd probably do this from a form rather from a table as it's much more
flexible in how you can express the logic.

Sorry, I am using a form based on the timesheet table I described, I should
have said that.

Look into using form's beforeupdate event and setting Cancel=True if the
validation fails.

I'm sorry, but I'm not sure where you are going with this...could you
explain a bit more?

Thanks,
Billiam
 
B

Banana

Basically you use VBA to validate the dates. In form's design view, you
would select the form in the properties windows, and under Event tab,
select BeforeUpdate and choose "Event Procedure". Click the ellipisis
button to go to the VBA editor which will have created the BeforeUpdate
event handler for you. In that event handler the VBA may look like this:

Private Sub MyForm_BeforeUpdate(Cancel As Integer

If Not Me.<TestDate> > Me.<StartDateControl> And
Not Me.<TestDate> < Me.<EndDateControl> Then
Cancel = True
End If

End Sub

Replace all the identifier inside the <>s (and delete the <> as well)
with the actual names of your controls on the form where you want to
check the dates for comparison.

HTH.
 
B

Billiam

Thank you very much for the detailed answer...I do try, and did come up with
this which seems to be working great!

Private Sub DateWorked_BeforeUpdate(Cancel As Integer)

If Me.DateWorked < Me.PayPeriodFrom Or Me.DateWorked > Me.PayPeriodTo Then
MsgBox "You have entered a day OUTSIDE of the Pay Period Chosen!"
Cancel = True
End If
End Sub

Thank you very much for your help, I really appreciate it, and learned a few
new things, too!
Have a great day!
Billiam
 
B

Billiam

Hello Ken,

It's always an honour when you respond! Yes, I think your approach might
make more "sense" in that the error cannot occur at all your way...

Unfortunately, like today AND yesterday, I am working on a timesheet DB for
my non-profit organization, which I had hoped would be finished
tommorrow...gulp. Oh well, if they're that mad I guess they"ll just have to
find another sucker dumb as I am , and good luck with that, because I must be
dumb to be working on this glorious weather day, LOL! My real point being, I,
at least, work on weekends, so I would need to add that in.

Perhaps I could ask your opinion, Ken, as to handling large blocks of time
easily for the enduser when they are entering in vacation time or sicktime...

Currently, I have only given the enduser a DateWorked field, now going to be
a cbo based on the payperiod thanks to you (well, at least I hope it will)
and a cboOtherTime for vacation day, sick day, statuatory holiday which have
their own cboWorkCode to display them.

I suppose I may be allowed by the bookeeper to have one entry for vaction,
and the cboOtherTime with a values of 8 hours to 80 hours, however, I think
it would be nice to be able to have the enduser click on a report so they can
see how many days they have used during the year,when they used them, and I
suspect then that this would not be the way to do it. For that matter, I
suppose someone could be sick for quite a number of days as well...

Any advice on how to handle this would be sincerely appreciated!
Warm Regards, and thanks for taking the time out of your day to help me...I
hope someone passes that kindness on to you ten fold!

Best Regards,

Billiam
KenSheridan via AccessMonster.com said:
Another approach you might like to consider is to use a combo box as the
control bound to the DateWorked field. You can then restrict its list to
the available dates within the pay period by setting its LimitToList property
to false (No) and rebuilding its list when the PayPeriodFrom and PayPeriodTo
dates are updated. You can also restrict the list to working days, which for
the following example I've assumed to be Monday to Friday, and exclude public
holidays by storing these in a HolDate column in a PubHols table. To do this
add the following function to the form's module:

Private Function UpdateWorkDates(varFrom, varTo)

Dim ctrl As Control
Dim strCriteria As String
Dim dtmDate As Date

Set ctrl = Me.DateWorked

ctrl.RowSourceType = "Value List"
ctrl.RowSource = ""

If Not IsNull(varFrom) And Not IsNull(varTo) Then
' if DateWorked control's current value
' is outside date range then set to Null
If ctrl < varFrom Or ctrl > varTo Then
ctrl = Null
End If

For dtmDate = varFrom To varTo
strCriteria = "HolDate = #" & _
Format(dtmDate, "yyyy-mm-dd") & "#"
' if date is at weekend exclude from list
If Weekday(dtmDate, vbMonday) < 6 Then
' if date is a public holiday exclude from list
If IsNull(DLookup("HolDate", "PubHols", strCriteria)) Then
ctrl.AddItem dtmDate
End If
End If
Next dtmDate
Else
' if either start or end dates of pay period
' are Null set DateWorked control to Null
ctrl = Null
End If

End Function

Then in their properties sheets set the After Update event property of both
the PayPeriodFrom and PayPeriodTo controls, and the form's On Current event
property to:

=UpdateWorkDates([PayPeriodFrom],[PayPeriodTo])

Ken Sheridan
Stafford, England
Thank you very much for the detailed answer...I do try, and did come up with
this which seems to be working great!

Private Sub DateWorked_BeforeUpdate(Cancel As Integer)

If Me.DateWorked < Me.PayPeriodFrom Or Me.DateWorked > Me.PayPeriodTo Then
MsgBox "You have entered a day OUTSIDE of the Pay Period Chosen!"
Cancel = True
End If
End Sub

Thank you very much for your help, I really appreciate it, and learned a few
new things, too!
Have a great day!
Billiam
Basically you use VBA to validate the dates. In form's design view, you
would select the form in the properties windows, and under Event tab,
[quoted text clipped - 48 lines]
thankful for some help on this...
Billiam
 
B

Billiam

Thanks again, Ken, for a thought provoking answer!
Best Regards,
Billiam
KenSheridan via AccessMonster.com said:
Billiam:

When it comes to non-worked time which is credited to an employee, i.e. for
which they are paid, such as annual, public or concessionary holidays, sick
time, compassionate leave etc, there are I think basically two options.

Firstly they can all be treated as one entity type, with the 'category' as an
attribute of the entity type. In this case the time would be entered in a
single table, differentiating worked from non-worked times by the category.

The second is to regard them as different entity types, with a table for each
category. This makes the interface design easier as the times can be entered
as durations rather than start and end times, e.g. as the number of days.

However, I'm not keen on the latter approach as I think its really bending
the reality to suit the model rather than the model reflecting the reality.
My gut feeling is that we are really dealing with a single entity type and
the model should reflect this. It does mean, however, that for non-worked
time computations its necessary to assume standard start and end times per
day, or half day if pre and post lunch times are recorded as two rows rather
than a day as a single row with a subtraction for lunch. Wherever I've
worked we've always recorded time as separate pre and post lunch start and
end times.

If a single table is used then there needs to be some machinery for entering
periods of leave en bloc rather than having to enter each day separately.
This is not too difficult, however, as it can be done via a separate form to
the day-to-day data entry form for normal worked time. At its simplest the
user would enter either start and end dates, or a start date and number of
days, the category (annual leave, sick leave etc) and on confirmation via a
button some code would loop through each day in the range, inserting rows
into the table with the standard start and end times per day or half-day,
excluding the weekend and public/concessionary holiday days in the same.
These standard times should themselves be values in a table which can be
referenced in the SQL statements to insert the rows.

For reporting purposes it would then be a simple task to design a report
grouped by year (either calendar or accounting year), employee and time
category and restricted only to non-worked categories, which counts the
number of rows per category, dividing the result by two if two rows (pre and
post lunch) per day are used.

One caveat, however. The real world is not always neatly arranged. As an
example my own wife works part time, roughly half the standard working week
of her organisation. When she takes a public holiday, therefore, the time
with which she is credited is a pro rata portion of a standard day. As it
happens public holidays here are usually a Monday, which is a day on which
she normally works a full day, so she is benefiting from a full days absence
from work, but as she is only credited with the pro rata portion of a
standard day she then has to work an additional half-day during that week to
make up the difference. Consequently the system at her workplace has to take
account of this, crediting her with half a day's time for the public holiday,
and also with the additional half day she works in that week. The latter is
no problem of course as she logs in and out on that day, but if the system
applied a blanket full day's credit to everyone for the public holiday then
she'd be credited with too much time. In database terms one way of looking
at this is that the credited time for a public holiday is not functionally
dependent on the holiday per say (i.e. on the key of the holidays table), but
on that and the employee, i.e. on the key of a table which models the
relationship between employees and public holidays, in which there will have
to be columns for the standard public holiday times per employee. Or an
alternative approach would be to have a credited standard time per public
holiday, and for part-time employees like my wife, apply a factor to this on
the basis of her standard weekly hours as a proportion of those of full time
employees. I've no idea exactly how their system does it (not always
efficiently to judge by the number of times she has to get her times
corrected!), but however it is done, it does serve to illustrate the need to
take such variation in work patterns into account when designing timesheet
applications.

Ken Sheridan
Stafford, England
Hello Ken,

It's always an honour when you respond! Yes, I think your approach might
make more "sense" in that the error cannot occur at all your way...

Unfortunately, like today AND yesterday, I am working on a timesheet DB for
my non-profit organization, which I had hoped would be finished
tommorrow...gulp. Oh well, if they're that mad I guess they"ll just have to
find another sucker dumb as I am , and good luck with that, because I must be
dumb to be working on this glorious weather day, LOL! My real point being, I,
at least, work on weekends, so I would need to add that in.

Perhaps I could ask your opinion, Ken, as to handling large blocks of time
easily for the enduser when they are entering in vacation time or sicktime...

Currently, I have only given the enduser a DateWorked field, now going to be
a cbo based on the payperiod thanks to you (well, at least I hope it will)
and a cboOtherTime for vacation day, sick day, statuatory holiday which have
their own cboWorkCode to display them.

I suppose I may be allowed by the bookeeper to have one entry for vaction,
and the cboOtherTime with a values of 8 hours to 80 hours, however, I think
it would be nice to be able to have the enduser click on a report so they can
see how many days they have used during the year,when they used them, and I
suspect then that this would not be the way to do it. For that matter, I
suppose someone could be sick for quite a number of days as well...

Any advice on how to handle this would be sincerely appreciated!
Warm Regards, and thanks for taking the time out of your day to help me...I
hope someone passes that kindness on to you ten fold!

Best Regards,

Billiam
Another approach you might like to consider is to use a combo box as the
control bound to the DateWorked field. You can then restrict its list to
[quoted text clipped - 72 lines]
thankful for some help on this...
Billiam
 

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