Solved

Access: force a user to choose a friday from the calendar?

Posted on 2014-10-15
13
153 Views
Last Modified: 2014-10-17
On one of my Access forms I have a field that the user can add a date to. It formatted to 'date'  so the little calendar appears when they click on it and they chose the date from there.

Is there a way to limit their choice to a Friday?
0
Comment
Question by:Megin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40383127
I think you cannot do that but you can set a control afterwards to check is the friday selected:


If Weekday(Me.DatePicker) <> 5 Then
  MsgBox "You Can Select only Friday!"
Else
  Me.DateTextBox = Me.DatePicker
End If

Open in new window

0
 
LVL 58
ID: 40383979
As samo4fun indicated, you can't modify the calendar that I'm aware of, but you can check if the weekday for a date is a friday in the controls beforeupdate event.

Do:

Cancel = True

 if an error occurs.   This will stop the control from accepting the value

Jim.
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 40384571
Friday is day 5 of the week if it starts on Monday.  It is day 6 if the week starts on Sunday.  In the US we generally use Monday as the start of the week but you can override that if necessary.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 24

Expert Comment

by:Bitsqueezer
ID: 40387558
Hi,

normally the user should know that he should only choose a Friday, i.e. through a hint on the form or anything else like that.
So the more userfriendly method would be to check the chosen date after input and programmatically change the date to the Friday date of the same week. On this way the user can click on any date in a week and automatically gets the Friday date which is better than choosing a date and annoy him with a message box which says "hehehe...silly user, you have again chosen the wrong day, try it again and if you do not choose a Friday I will come back to laugh at you again!"
As said above, the user should already know to choose a Friday so he will not be surprised that the date changes to the Friday date of the same week, he will instead love the comfort.

Cheers,

Christian
0
 

Author Comment

by:Megin
ID: 40387573
samo4fun: That looks great, but I can't use Me.DatePicker. DatePicker is not available to me.

Bitsqueezer: That would be fantastic, but I have no idea where to start with that. Can you help me out further?
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40387575
You need to download it and register it to your system..

Download here : http://www.microsoft.com/en-us/download/details.aspx?id=10019

then use this steps to register it http://support.microsoft.com/kb/249873

Than you will be able to use it
0
 
LVL 37

Expert Comment

by:PatHartman
ID: 40387581
The date picker has been integrated since A2007.  It is automatically activated for any control bound to a field with a date data type.  To make an unbound control a "date",  you need to specify a date format for the control.
0
 

Author Comment

by:Megin
ID: 40387588
Sorry. I don't think I was clear.

The actual datepicker attached to the field works fine.
The problem is using it in the VBA code. It is not a method/data member that is available to me.
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40387589
maybe it is Me.DatePicker1?
0
 

Author Comment

by:Megin
ID: 40387590
And I can't download it. I am on a network and am not an administrator. Downloading it requires administrator rights/
0
 

Author Comment

by:Megin
ID: 40387591
When I type in "Me.", nothing beginning with the word "Date" shows up.
0
 
LVL 24

Accepted Solution

by:
Bitsqueezer earned 500 total points
ID: 40387695
Hi,

as you already said in your initial post you already have a date picker so I guess you have at least A2007. So you don't need to download anything here.

The date picker itself cannot be programmed, it is automatically activated if the field is of date type and you didn't explicitly deactivated it.

But that's not needed, let the user simply choose a date of the week he want and then use i.e. the AfterUpdate event of the textbox to change the date to the Friday date.

If your textbox has the name "MyDate" it would be as simple as that:
Private Sub MyDate_AfterUpdate()
    Me.NyDate = DateAdd("d", 5 - Weekday(Me.MyDate, vbMonday), Me.MyDate)
End Sub

Open in new window


Cheers,

Christian
0
 

Author Closing Comment

by:Megin
ID: 40387704
That is perfect!!!!!

Just what I needed. Thank you!!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question