How do I setup a date field property that allows only Saturdays?

  • Follow


For example: 

03/13/2010 would be fine, as that is a Saturday.  03/12/2010 would return an 
error message as it is a Friday.

How would I create a field property for this, or would I use a different 
aspect of Access creation?
0
Reply Utf 3/12/2010 2:44:01 AM

jaymalea wrote:
>For example: 
>
>03/13/2010 would be fine, as that is a Saturday.  03/12/2010 would return an 
>error message as it is a Friday.
>
>How would I create a field property for this, or would I use a different 
>aspect of Access creation?

Private Sub txtSaturday_BeforeUpdate(Cancel As Integer)
    If Not Weekday(Me.txtSaturday) = vbSaturday Then
        MsgBox "Not a Saturday!"
        Cancel = True
    End If
End Sub

-- 
Message posted via http://www.accessmonster.com

0
Reply PieterLinden 3/12/2010 3:17:07 AM


Open the table in design view, select the Date/Time field, and set these 
properties:
- Validation Rule:    ([SatOnly] Mod 7)=0
- Validation Text:    Must be a Saturday

Replace the SatOnly with the name of your field.

-- 
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.


"jaymalea" <jaymalea@discussions.microsoft.com> wrote in message 
news:A0A534FE-E315-4E60-979C-35BBF20B21F2@microsoft.com...
> For example:
>
> 03/13/2010 would be fine, as that is a Saturday.  03/12/2010 would return 
> an
> error message as it is a Friday.
>
> How would I create a field property for this, or would I use a different
> aspect of Access creation? 

0
Reply Allen 3/12/2010 5:52:08 AM

On Thu, 11 Mar 2010 18:44:01 -0800, jaymalea
<jaymalea@discussions.microsoft.com> wrote:

>For example: 
>
>03/13/2010 would be fine, as that is a Saturday.  03/12/2010 would return an 
>error message as it is a Friday.
>
>How would I create a field property for this, or would I use a different 
>aspect of Access creation?

Might it not be better to have the textbox just adjust itself to the next (or
previous) Saturday instead? You can use DateAdd() in the textbox's afterupdate
event to reset the date:

Private Sub txtSaturday_AfterUpdate()
If Weekday(Me!txtSaturday) <> vbSaturday Then
   Me!txtSaturday = DateAdd("d", 7 - Weekday(Me!txtSaturday))
  MsgBox "Adjusted date to Saturday, " & format(Me!txtSaturday, "dd-mmm-yyyy")
End If
End Sub
-- 

             John W. Vinson [MVP]
0
Reply John 3/12/2010 6:24:50 AM

3 Replies
234 Views

(page loaded in 0.133 seconds)

Similiar Articles:
















7/22/2012 9:17:47 AM


Reply: