473,491 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Validation Rule Concerning Current vs Coming year

2 New Member
I have an Access 2010 database that I enter purchase orders into. By default when I enter a ship date the program inputs the current year which isn't a big deal until November and December of a given year, at that time the orders I'm entering have a mix of ship dates of the current and the coming year. How can I make the program recognize that when I enter a ship date of say, January whatever, I mean January of the coming year and not the current year?
Dec 17 '13 #1
5 1429
Seth Schrock
2,965 Recognized Expert Specialist
I believe that you are talking about the ability to just type in the day and month of the date and then Access fills in the year. If this is the case, then I would try something like the following: In the control's AfterUpdate event, test the value to see if it is less than today's date (using the Date function). If it is, then use the DateAdd function to add 1 year to it. For example, if you control name is txtShipDate, then your code would be something like this:
Expand|Select|Wrap|Line Numbers
  1. If Me.txtShipDate < Date Then
  2.     Me.txtShipDate = DateAdd("yyyy", 1, Me.txtShipDate)
  3. End If
Dec 17 '13 #2
NeoPa
32,556 Recognized Expert Moderator MVP
Does this question even concern the Validation Rule property at all? It sounds like probably not.

As Seth says, if you are talking about the default year being added to a date when omitted from the entry data, you will need to check the value input after it's been submitted. Or you can check the characters entered, but that's much more involved.
Dec 18 '13 #3
zmbd
5,501 Recognized Expert Moderator Expert
tomdible

By default, all dates entered are assumed by the program and the OS to be for the current year.

Let's take today 2013-12-18 and your example that you are entering a January date. That you want to enter 01/05 (mm/dd) and have the system assume that you mean 2014-01-05 and not 2013-01-05 is only logical if and only if there would never be a time when today (or later) you would not actually need to enter 2013-01-05.

Seth is fairly close in code.
Neopa is correct in that the date needs to be evaluted at the point of entry.

Here's what I would do:
On the form, checkbox, with title: "set all dates from Jan thru October for next year", default unchecked, default hidden (the caption could be changed in the onload event for thru nov if current Month() is dec)

At the declarations level of the form have a boolean for "henpeckonce"

On Load event, check current date Month() if November or December then Checkbox is set true and made visible and "henpeckonce" set to true

Before update event check for the for the control:
1) if the checkbox is visible the proceed to 2 else bail
2) if Henpeck is true and the checkbox is true then msgbox to remind them that the checkbox is toggled true and that dates with Jan thru Oct (with conditionl we can change the string to Jan thru Nov) will be entered for next year, is this OK, use the YES/NO buttons with NO defaulted.
2a) if vbYes, then set Henpeck to false and proceed
2b) if vbNo, then set Henpeck to false, set the checkbox to false, and bail
3) if the checkbox is true then check the date entered, if the Month() Jan thru Oct (or nov if current dec) then check the year:
3a) if year<current then prompt for action
3b) if year=current then +1
3c) if year>current then leave alone
I leave the code for OP
Dec 18 '13 #4
tomdible
2 New Member
Thank you all for your time. It appears the fix is beyond the scope of my ability and having to type the year as needed seems to be the best course of action for us.
Dec 18 '13 #5
zmbd
5,501 Recognized Expert Moderator Expert
We're here for you should you like to make the attempt. (^_^)

I've PM'd you a list of reference sites that should help you dive into the deep-end of Access design and programing.... Once you start... you never stop... come join us... become part of those lost and addicted to the VBA dark-side
(insert dark and sinister laughter)

-z
Dec 18 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2674
by: Joey P | last post by:
Hi all, I am doing a project for university whereby i have to implement a simple database related to a frozen foods company. I am having some trouble though creating a validation rule for one...
6
3675
by: Chuck | last post by:
A97. A database has a table: tblA which has a single text field, B. It is a primary field, indexed and no duplicates. It is used as a lookup for table tblC. A form based on tblA is used to add...
2
2355
by: Vladi | last post by:
Experience is highly requested. I can't find solution for the following problem: I am making VBA code for moving/modifying data from "old" tables into "new" ones. In fact, this is part of the...
4
2704
by: ron | last post by:
I have a access based guest book. I want to create a validation rule to block certain words or parts of a srting. How do i do this? ie: this is a nice site. come visit my porn site at www.abc.zy...
4
2727
by: Anansie | last post by:
Hello! I have a problem with this table PRODUCTS, it has the following fields: -Product id: Number, single, primary key -Status: validation rule with the following restrictions: in stock,...
10
5683
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
2
1560
by: Amers01 | last post by:
Dear Can some one tell how can i put a validation rule like CITddmmyy0001 basically I am preparing a database for my video shop and want that id to be like this Actually CIT my compny nick...
3
1278
by: KPR1977 | last post by:
I want to set a validation rule that will not allow me to input data in field1 in TableA that is not found in TableB under field2. Basically, Table B under field 2 has the following row entries: ...
1
2062
by: MLH | last post by:
Anyone remember if A97 append query failure would ever report data breaking validation rule when such was not the case. I have an old SQL statement - several years old now. I've encountered a case...
7
2836
by: Sylvio | last post by:
Hello, Here is my question. I've got several check boxes on my form (yes/no questions for users). And one check box that says "None of the above". If the latter is ticked: 1) all other check...
0
7118
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6862
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
1397
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.