473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to avoid date overlapping in MSAccess

2
Hi to all in forum.
It is my first post here.
I am quite new in MsAccess programming.
Here is a problem which i am facing to.
I want to keep records of employees CV's. More specifically i want to keep the data regarding experience but i need to avoid time overlapping. I use the following tables - among others- EmployeeTb(means employee's table, Edu_ExperTb (means educational experience table) and Prof_ExperTb (means all other experience except educational table). Each employee can have multiple educational or professional experience. The table description are:

--> EmployeeTb: Emp_id, Name, ....(Emp_id - Primary Key)
--> Edu_ExperTb:Emp_id,Edu_start_date, Edu_end_date (Emp_id is Foreign Key of EmployeeTb)....
--> Prof_ExperTb:Emp_id,Prof_start_date, Prof_end_date (Emp_id is Foreign Key of EmployeeTb)....

My problem is to prohibit entering date values through a proper form , which are overlapped. For example if an employee has 2 or more periods of educational experiences, each one cannot start before ending the previous one. E.g. if the first employee's educational experience was between 1 Jan 2006 and 1 Oct 2006, any other educational for the same employee either should be begin after 1 oct 2006 or shall end before 1 of Jan 2006.
The same concept shall be applied for the Professional experience.

Furthermore i want to avoid time overlapping between educational and professional experience. This means that an employee is not allowed to have both educational and professional at the same time.


Thanks in advance for your time and possible quick response.
Oct 31 '06 #1
4 4694
NeoPa
32,556 Expert Mod 16PB
This is too complex to do it all for you, but you sound as if the right lines is all you're looking for here.
Basically, for each date (Start & End on the form), you need to define a select query returning any records where the form date is BETWEEN the start and end dates of the record.
Then, if the count of all the records is 0 - it's a valid date - if > 0 then bad date.
This would have to be done for both dates and also, both Edu_ExperTb & Prof_ExperTb tables must be checked (you could do this either with a union query or with an OR clause in your SQL.

Let us know if this is enough - I have to say, if it's not I can't promise to do it all out longhand, but it is an interesting question so, who knows.
Oct 31 '06 #2
MMcCarthy
14,534 Expert Mod 8TB
--> EmployeeTb: Emp_id, Name, ....(Emp_id - Primary Key)
--> Edu_ExperTb:Emp_id,Edu_start_date, Edu_end_date (Emp_id is Foreign Key of EmployeeTb)....
--> Prof_ExperTb:Emp_id,Prof_start_date, Prof_end_date (Emp_id is Foreign Key of EmployeeTb)....

As an example

In the form where the user is entering the Edu_start_date you can put the following in the After Update event (if you don't know how come back and I'll tell you).

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Edu_start_date_AfterUpdate()
  3.  
  4.   If Me.Edu_start_date < DMax("[Edu_end_date]", "Edu_ExperTb", "[Emp_id]=" & Me.Emp_id)
  5.     Msgbox "This date is before the finish date of last course", vbOkOnly
  6.     Me.Edu_start_date = Null
  7.     Me.Edu_start_date.SetFocus
  8.   End If
  9.  
  10. End Sub
  11.  
  12.  
Nov 1 '06 #3
gzaxar
2
--> EmployeeTb: Emp_id, Name, ....(Emp_id - Primary Key)
--> Edu_ExperTb:Emp_id,Edu_start_date, Edu_end_date (Emp_id is Foreign Key of EmployeeTb)....
--> Prof_ExperTb:Emp_id,Prof_start_date, Prof_end_date (Emp_id is Foreign Key of EmployeeTb)....

As an example

In the form where the user is entering the Edu_start_date you can put the following in the After Update event (if you don't know how come back and I'll tell you).

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Edu_start_date_AfterUpdate()
  3.  
  4.   If Me.Edu_start_date < DMax("[Edu_end_date]", "Edu_ExperTb", "[Emp_id]=" & Me.Emp_id)
  5.     Msgbox "This date is before the finish date of last course", vbOkOnly
  6.     Me.Edu_start_date = Null
  7.     Me.Edu_start_date.SetFocus
  8.   End If
  9.  
  10. End Sub
  11.  
  12.  
Thanks mmccarthy. It seems it works ok for either check Edu_Start_date or Prof_start_date. You saved me out of a lot of trouble.

Also i want to check if Edu_Start_date or Edu_End_date overlaps with Prof_start_date or Prof_end_date.
I use 2 sub forms to insert values to tables. The first one is Edu_Exper_Frm regarding Edu_ExperTb and the other is Prof_Exper_Frm regarding Prof_ExperTb. The parent form is the Emp_Frm, which shows all data from EmployeeTb table.
Is there a way to check, at the same time, if a start or end date from educational experience is overlapped with the one from the start or end date of Professional experience?

Thanks again.
Nov 1 '06 #4
NeoPa
32,556 Expert Mod 16PB
Private Sub Edu_start_date_AfterUpdate()

If Me.Edu_start_date < DMax("[Edu_end_date]", "Edu_ExperTb", "[Emp_id]=" & Me.Emp_id)
Msgbox "This date is before the finish date of last course", vbOkOnly
Me.Edu_start_date = Null
Me.Edu_start_date.SetFocus
End If

End Sub
Correct me if I'm wrong, but I think, rather than checking that the entered date is simply after the latest date in the table, gzaxar is after something to check through all the start and end dates in both tables to make sure it clashes with none of them.
The difference would be that it needs to handle gaps between previously entered date ranges.
For instance (and just including the Edu table for simplicity) :
If he went on courses between 1 and 31 Jan for both 1996 and 1997, then he should still be able to enter that he went on another course in August of 1996.

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtStart_Date_BeforeUpdate(Cancel As Integer)
  2.     Dim strDate as String
  3.  
  4.     'We format the date string to include the '#' delimiters
  5.     strDate = Format(CDate(txtStart_Date), "\#m/d/yyyy\#")
  6.     Cancel = DMin("(" & strDate & " Between [Edu_Start_Date] And [Edu_End_Date])", _
  7.                   "[Edu_ExperTb]", _
  8.                   "([Emp_id]=" & txtEmp_id & ")") OR _
  9.              DMin("(" & strDate & " Between [Prof_Start_Date] And [Prof_End_Date])", _
  10.                   "[Prof_ExperTb]", _
  11.                   "([Emp_id]=" & txtEmp_id & ")")
  12.     If Cancel then _
  13.         Call MsgBox("This date clashes with an existing date range", _
  14.                     vbOkOnly)
  15. End Sub
This assumes the itmes on the form are named as the fields in the record but with "txt" at the front to denote a TextBox object BUT the start and end dates do NOT include the Edu / Prof bit as then they can be reused on the other form without change.
So, Item_id -> txtItem_id
Edu_Start_Date -> txtStart_Date
Edu_End_Date -> txtEnd_Date
Prof_Start_Date -> txtStart_Date
Prof_End_Date -> txtEnd_Date

A similar function would be required for the other date field on each form.
Nov 1 '06 #5

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

Similar topics

11
by: Max M | last post by:
I am writing a "find-free-time" function for a calendar. There are a lot of time spans with start end times, some overlapping, some not. To find the free time spans, I first need to convert the...
4
by: Lynn | last post by:
On a form I have Date_Start Date_End I have a new Date_Start1 Date_End1 which the use inputs. I need to validate that Date_Start1 and...
0
by: Chris Q. | last post by:
I am creating a custom control that contains a list view with dates and times. I need to make sure that times do not overlap. I would like the control to determine if the overlap is occuring with the...
2
by: John Baker | last post by:
HI; I have a table where the user is entering data which shows scheduling for member of teams. One problem we have encountered is that sometimes the inputter (is this a word) puts in dates for...
3
by: Lyn | last post by:
Hi, I am developing a project in which I am checking for records with overlapping start/end dates. Record dates must not overlap date of birth, date of death, be in the future, and must not...
2
by: monadel | last post by:
I have a problem with checking the overlapping date. Basically I am developing a database using MS Access (VB scripts) and SQL queries. I have 2 tables which are empTable and empLeaveTable. In a...
11
by: robtyketto | last post by:
Greetings, I'm using Flash MX connecting to an MS Access database via JET. I've stored dates using Flash/Jet into my database as 'dd/mm/yyyy hh:mm:ss' into a DATE/TIME field. However I can't...
6
chandru8
by: chandru8 | last post by:
hi to all i am using vb6.0 and msaccess 2003 iam inserting date like the query mentioned below strSql = "Insert into table1 values (#" & Date & "# )" the problem is .., for the 1ST date...
3
chandru8
by: chandru8 | last post by:
hi to all i am using vb6.0 and msaccess 2003 iam inserting date like the query mentioned below strSql = "Insert into table1 values (#" & Date & "# )" the problem is .., for the 1ST date...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...
0
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...
0
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
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,...

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.