Restricting data entered in a form field

  • Thread starter najah via AccessMonster.com
  • Start date
N

najah via AccessMonster.com

Hello All,

I hope you can help me. I've created a form that allows employees to enter
their timesheet.

In my main form I have two bound fields--[StartDate] and [EndDate] which
represent the biweekly pay period

I have a subform called TimeSheetHours in which they enter specific details
of their daily workday.

One of the fields is [Date]

Here is my Problem:

I don't want the employees to be able to enter a date in this field that is
outside of the [StartDate] and [EndDate] entered on the main form. In other
words the [Date] has to be >=[StartDate] and <=[EndDate]. Can this be done
and if so how? Please Help!
 
A

Al Camp

Najah,
First, don't use the name [Date] for a field name. It's a reserved word in Access and
can cause problems. Call it TSheetDate, or something like that.

I'll use that name in my response...

On the Before Update event of [TSheetDate]...

Private Sub TSheet_BeforeUpdate(Cancel As Integer)
If TSheetDate < Forms!MainFormName![StartDate] OR TSheetDate >
Forms!MainFormName![EndDate] Then
Beep
MsgBox "Date must be within...etc... "
TSheetDate.Undo
Cancel = True
End Sub
 
N

najah via AccessMonster.com

Thanks Al,

That worked out for me. Also thanks for the Date field advice, I didn't know
that. I'm a fairly new access user so any advice helps me to become more
proficient!

Najah

Al said:
Najah,
First, don't use the name [Date] for a field name. It's a reserved word in Access and
can cause problems. Call it TSheetDate, or something like that.

I'll use that name in my response...

On the Before Update event of [TSheetDate]...

Private Sub TSheet_BeforeUpdate(Cancel As Integer)
If TSheetDate < Forms!MainFormName![StartDate] OR TSheetDate >
Forms!MainFormName![EndDate] Then
Beep
MsgBox "Date must be within...etc... "
TSheetDate.Undo
Cancel = True
End Sub
Hello All,
[quoted text clipped - 15 lines]
words the [Date] has to be >=[StartDate] and <=[EndDate]. Can this be done
and if so how? Please Help!
 

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