473,903 Members | 5,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Date validation within MS Access

8 New Member
I must start this posing by making the point that I am NOT a VB programmer and I'm something of a Newbie to MS Access. I can program in a number of languages (Java, Javascript, PERL,PHP and TCL) but have never actually learnt VB so my request is that you bear this in mind if you plan on replying to this post.

My request for help is as follows:

I have an MS Access database in which one of the tables within it contains two date fields called "StartDate" and "EndDate" respectively. The table in question is designed to hold entity specific data on conferences hosted by a conference hosting company. Each row in the database contains a new record (entity instantiation) of a specific conference hosted by the company.

The field names are self-explanatory in that the StartDate refers to the date at which a conference started or starts and the EndDate fields refers to the either a future date when the conference will end or when it ended some time in the past. The problem I am having is that I need to apply validatory constraints to both of these fields that are not easily achieved with the application and so therefore I suspect that I need to resort to some VB code.

To be clear, there are cerrtain rules that I need to apply (constraints) to these date fields to ensure that any values entered via a conrresponding entry form or indeed via a datasheet view for a completely new or existing record do not violate these rules. The rules are:

START DATE:

- The value entered cannot be today's date - i.e, it must be greater than today's date and therefore some date in the future.

- The value entered can't be after the value entered in the end date as this mean that in effect a conference could never start.

END DATE:

- The value entered cannot be today's date - i.e, it must be greater than today's date and therefore some date in the future.

- The value entered cannot be before the value entered in the start date field as this would imply that the conference had already finished and all data about conferences will always be entered into the database before the actual start of a conference.

I do not know whether I can utilise code that will operate at the datasheet view level or whether it can operate only via a form but either way, I hope what I'm trying to achieve is clear. The question then is how to do this. I suspect that I am going to need to use VB code which is why I mentioned not being a VB programmer at the outset.

I did think of trying to achieve this by means of two additional database tables: - one called, something like: TBLConferenceSt artDates and another called: TBLConferenceEn dDates. Given that each record in the main conference details table has a unique ID assigned to it as a primary key (of datatype Integer), one could reference the conference start date and conference end date tables via a foreign key whilst maintaining referential integrity. The task then would be to use a the result of lookup query as the basis for enforcing the validation rules. One could look up the specific start date for a given conference ID, and vice-versa for an end date but I do not know whether it's possible to have a query run and then use the result of a query as a validation rule within Access. If it is possible, I'd love to know how this is achieved.

Any ideas with an explanation as to how any code works, would be very gratefully received.
Nov 27 '07 #1
3 6006
missinglinq
3,532 Recognized Expert Specialist
Having separate tables for start dates and end dates is abit too much normalization! Assuming you're doing your data entry thru a form (and you should never do data entry thru the table) this should do the job!

Expand|Select|Wrap|Line Numbers
  1. Private Sub EndDate_BeforeUpdate(Cancel As Integer)
  2. If IsNull(Me.StartDate) Then
  3.   MsgBox "You Must Enter a Start Date Before Entering an End Date !"
  4.     Cancel = True
  5.     Me.EndDate.Undo
  6.    End If
  7.  
  8. If Me.EndDate < Me.StartDate Then
  9.   MsgBox "End Date Must Be The Same or Later Than The Start Date !"
  10.   Cancel = True
  11.   Me.EndDate.SelStart = 0
  12. End If
  13. End Sub
  14.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub StartDate_BeforeUpdate(Cancel As Integer)
  2. If Not StartDate > Date Then
  3.   MsgBox "Start Date Must Be a Date In The Future !"
  4.   Cancel = True
  5.   Me.StartDate.SelStart = 0
  6. End If
  7.  
  8. If Not IsNull(Me.EndDate) Then Me.EndDate = ""
  9.  
  10. End Sub
  11.  
  12.  
It takes care of your validation and, in case the start date is entered incorrectly and then editted, it requires that the end date be re-entered, so that it is again validated.

Welcome to TheScripts!

Linq ;0)>
Nov 27 '07 #2
Harlequin
8 New Member
Having separate tables for start dates and end dates is abit too much normalization! Assuming you're doing your data entry thru a form (and you should never do data entry thru the table) this should do the job!

Expand|Select|Wrap|Line Numbers
  1. Private Sub EndDate_BeforeUpdate(Cancel As Integer)
  2. If IsNull(Me.StartDate) Then
  3.   MsgBox "You Must Enter a Start Date Before Entering an End Date !"
  4.     Cancel = True
  5.     Me.EndDate.Undo
  6.    End If
  7.  
  8. If Me.EndDate < Me.StartDate Then
  9.   MsgBox "End Date Must Be The Same or Later Than The Start Date !"
  10.   Cancel = True
  11.   Me.EndDate.SelStart = 0
  12. End If
  13. End Sub
  14.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub StartDate_BeforeUpdate(Cancel As Integer)
  2. If Not StartDate > Date Then
  3.   MsgBox "Start Date Must Be a Date In The Future !"
  4.   Cancel = True
  5.   Me.StartDate.SelStart = 0
  6. End If
  7.  
  8. If Not IsNull(Me.EndDate) Then Me.EndDate = ""
  9.  
  10. End Sub
  11.  
  12.  
It takes care of your validation and, in case the start date is entered incorrectly and then editted, it requires that the end date be re-entered, so that it is again validated.

Welcome to TheScripts!

Linq ;0)>

Thank you!

This is exactly what I wanted. Not being a VB programmer, there is no way could have done this myself and so I'm extremely grateful.
Nov 28 '07 #3
missinglinq
3,532 Recognized Expert Specialist
Glad we could help! It was actually a nice little problem to work on! If you have any trouble post back.

Linq ;0)>
Nov 28 '07 #4

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

Similar topics

30
3715
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code seems unnecessarily long. For some while, the following approach has been given here :- function ValidDate(y, m, d) { // m = 0..11 ; y m d integers, y!=0
6
4858
by: MickG | last post by:
Hi, I am trying to validate these values, this seems to work fine for the phone number and name but I am trying to get the program to fail to submit and set the focus on the date when 2006 is selected and submitted. Thanks in advance for any help.
1
1634
by: Anatoly Kurilin | last post by:
Hi, I need to enter date into a control without a month day - just mm/yyyy. I tried to use format mm/yyyy. It displays date OK, but when I edit, it shows dd/mm/yyyy. What's the corret way o doing that? Thank in advance, AK
1
4713
by: Brendan Reynolds | last post by:
In an ASP.NET 1.1 app I have the following range validation control. This is an intranet app that will be used only within Ireland, so all date input is expected to be in dd/mm/yyyy format. <asp:RangeValidator id="varngRollCallDate" runat="server" ErrorMessage="Please enter a valid date in 'dd/mm/yyyy' format." ControlToValidate="txtDate" Display="Dynamic" Type="Date" MinimumValue="01/01/2006" MaximumValue="31/12/2006"...
17
5297
by: Petyr David | last post by:
Just looking for the simplest. right now my perl script returns an error messge to the user if the date string is invalid. would like to do this before accessing the server. TX
1
1913
by: jsredhar | last post by:
Dear Experts, I have two text boxes in my form (f1) i'm prompting the users to select the date from callender which is embeded within the from. when the users Pick the date from the calender.it will be displayed as mm/dd/yyyy format. i'm getting the from date value at textbox (FromDate) and to date value at another textbox(ToDate). i've to validate that the to date should not be lesser than that of from date validation must be check date...
6
8165
by: Ledmark | last post by:
Hello - I am in a class for Access 2007 Database apllication design and we are covering types of Validation rules. We have a problem that I'm trying to solve but have no idea how to go about writing it. We are building a database for a condo rental company and the rental transaction table includes an arrival date and a departure date. We need to write a table-level validation rule that indicates the departure date is seven days after the...
7
5980
by: sharsy | last post by:
Hi guys, I would like to setup a validation rule for a database in microsoft access that restricts data entry so that a certain field can only be filled in if another field has a specific answer (that is selected via a drop down list). Example Field1 - options are "In" or "Out" Field2 - options are "Join" or "Not Joining"
3
1175
by: dakshayini | last post by:
I have an RHTML(Ruby onrails) page contains a JavaScript validation function that is activated onSubmit. The function contains a series of IF statements to alert the user to any blanks contained in the form elements.i am using a pop up calender to enter the date to text field. i want to make sure a user enters a date, the date is valid ...but i should be able to enter only previous 7 days date..if it is not so i should display an...
0
9999
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9847
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11283
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10875
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9685
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4727
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 we have to send another system
3
3324
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.