Specific Date

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

Guest

In a form text box how can I require them to enter a specific date i.e.
sunday dates only. I have the format set to short date.

Thanks,
Corby
 
Hi Corby, Access has a WeekDay function that will tell you if the date is a
Monday, Tuesday .. .Sunday, however . . .. for such a restrictive list,
that is prone to people typing in more wrong dates that right, I'd be
tempted to use a combo / listbox to select the date. Then, you just present
the user with a list of "Sundays"
 
On the before update event of the field you can check the value enterd, if
the value doesnt match the criteria, display a message, and return to the
date field, until the value will be repaired

If not isnull(Me.DateFieldName) then
If Weekday(Me.DateFieldName) <> 1 then
msgbox "Day must be 1"
cancel = true ' wont let exit the field
end if
end if
 
Effective, but slow data entry. You will need code to create your row source
and have to look through 52 or so entries in the list. Here is a function
you can use that will do what you want.

Function IsItSunday(varCheckDate As Variant) As Boolean
Dim lngDayNum As Long
Dim dtmcheckdate As Date
On Error GoTo IsItSunday_Exit
If Not IsDate(varCheckDate) Then
MsgBox "Invalid Date"
IsItSunday = False
Exit Function
Else
dtmcheckdate = CDate(varCheckDate)
End If
lngDayNum = Weekday(dtmcheckdate, vbSunday)
If lngDayNum <> 1 Then
MsgBox Format(dtmcheckdate, "short date") & " is " _
& WeekdayName(lngDayNum, False, vbSunday) & vbNewLine _
& "Last Sunday was " & DateAdd("d", vbSunday - DatePart("w",
date), date) _
& vbNewLine _
& "Next Sunday is " & DateAdd("d", vbSunday + DatePart("w",
date), date)
IsItSunday = False
Else
IsItSunday = True
End If
Exit Function
IsItSunday_Exit:
MsgBox "Invalid Format"
IsItSunday = False
End Function

To call it, put this in the Before Update event of where you enter the date:
If Not IsItSunday(Me.MyDateControL) Then
Cancel = True
End If

I would also recommend setting the Input Mask of your control to "Short Date"
 

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

Back
Top