Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy DatePart ? 3

Status
Not open for further replies.

Utracman

Programmer
Mar 12, 2001
20
US
Ok.... searched several sites and can not find an example.

I know its the after update event and probally a datePart function but there may be a better way.

A97 Bound text box where a date is entered.

I need to only allow Monday, Tues, Wed or Thurs as acceptable dates. No Friday Sat or Sunday dates.

If Me.txtSdate = ?........ Then

How can I do this?

Thanks for the time

Dave To learn fron those who have mastered the art..... Saves many headaches!
 
Here is one way to go about it. In the before update event of your date textbox (I will call it txtDate) put this...

Private Sub txtDate_BeforeUpdate(Cancel As Integer)

If WeekDay(txtDate, vbMonday) > 4 Then

MsgBox "Sorry, this date is invalid. Date must be for Monday thru Thursday"
DoCmd.CancelEvent

End If

End Sub

Basically this checks the numerical number of the week. I used vbMonday so that the first day of the week would be Monday. This way Fri - Sun would have numbers 5 - 7. Now all I have to do is say that for all days greater that 4 (Thursday) give my message.

Good luck.
ljprodev@yahoo.com
ProDev, MS Access Applications B-)
 
Perfect!

Many thanks for the lesson

Dave To learn fron those who have mastered the art..... Saves many headaches!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top