Solved

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

Posted on 2014-10-15
13
145 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
  • 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 57
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 35

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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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 35

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
type of query 11 42
Access sql to sql server express 10 35
Access Changing Number to Date with Seperator 5 21
SQL multicriteria from ONE textbox 32 43
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

777 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