Hello all
I have these records on my Day Table for my complete database table please click here
1. M
2. T
3. W
4. TH
5. F
6. S
7. MTH
8. TF
9. WS
Let say if I have this existing schedule:
* ScheduleID = 10001
* StartTime = 8:30 AM
* EndTime = 1:00 PM
* Day = M
* Room = AVR
* Course = BSN
Then If I add this new entry
* ScheduleID = 10002
* StartTime = 9:00 AM
* EndTime = 10:00 AM
* Day = MTH
* Room = AVR
* Course = BSN
This should prompt a conflict in schedule because there is already a schedule for monday, then the new entry shouldn't be added. : )
Note: MTH means 'Monday' AND 'Thursday', I used this if they have both the same schedule. Because it would become redundant if add a new schedule for monday and add another for thursday with the same day, time, room and course. Also the same as TF and WS. I can only detect conflict if it is not a combination of both Days (e.g MTH, TF, ...) I really spend a lot of time regarding this issue. Please I really need your help : (
Here are my sample codes:
This was my original code, please please click here -
-
'Let say Day1='M' and Day2='TH' as we're going to used the example above
-
-
Public Function Conflict(ByRef adConnection As ADODB.Connection, ByRef adRecordset _
-
As ADODB.Recordset, ByRef Day1 As String, ByRef Day2 As String, ByRef Room As _
-
String, ByRef Course As String, ByRef Section As String, ByRef Semester As String, _
-
ByRef TimeStarted As Date, ByRef TimeFinished As Date) As Boolean
-
-
adRecordset.Open "Select * From LoadSchedules Where (DayA='" & Day1 & "'" & _
-
" And Rooms.Title='" & Room & "' And Courses.Title='" & Course & "' And " & _
-
"Sections.Title='" & Section & "' And Semester='" & Semester & "' And " & _
-
"(TimeStarted <= #" & TimeStarted & "# And " & _
-
"TimeFinished >= #" & TimeStarted & "#) Or (#" & TimeStarted & "#" & _
-
"<= TimeStarted And TimeFinished < #" & TimeFinished & "#) Or (#" & _
-
TimeStarted & "# <= TimeStarted And TimeStarted < #" & TimeFinished & "#)) Or " & _
-
"(DayB='" & Day2 & "'" & _
-
" And Rooms.Title='" & Room & "' And Courses.Title='" & Course & "' And " & _
-
"Sections.Title='" & Section & "' And Semester='" & Semester & "' And " & _
-
"(TimeStarted <= #" & TimeStarted & "# And " & _
-
"TimeFinished >= #" & TimeStarted & "#) Or (#" & TimeStarted & "#" & _
-
"<= TimeStarted And TimeFinished < #" & TimeFinished & "#) Or (#" & _
-
TimeStarted & "# <= TimeStarted And TimeStarted < #" & TimeFinished & "#))", _
-
dbConnection, 1, 1
-
-
'Checks if there is conflict
-
If adRecordset.RecordCount > 0 Then
-
Conflict = True
-
Else
-
Conflict = False
-
End If
-
-
And I also tried Between And Operator. It is still same results above. -
-
'Let say Day1='M' and Day2='TH' as we're going to used the example above
-
-
Public Function Conflict(ByRef adConnection As ADODB.Connection, ByRef adRecordset _
-
As ADODB.Recordset, ByRef Day1 As String, ByRef Day2 As String, ByRef Room As _
-
String, ByRef Course As String, ByRef Section As String, ByRef Semester As String, _
-
ByRef TimeStarted As Date, ByRef TimeFinished As Date) As Boolean
-
-
adRecordset.Open "Select * From LoadSchedules Where (DayA='" & Day1 & "'" & _
-
" And Rooms.Title='" & Room & "' And Courses.Title='" & Course & "' And " & _
-
"Sections.Title='" & Section & "' And Semester='" & Semester & "' And " & _
-
"(TimeStarted Between #" & TimeStarted & "# And #" & TimeFinished & "# Or " & _
-
"TimeFinished Between #" & TimeStarted & "# And #" & TimeFinished & "#)) Or " & _
-
"(DayB='" & Day2 & "'" & _
-
" And Rooms.Title='" & Room & "' And Courses.Title='" & Course & "' And " & _
-
"Sections.Title='" & Section & "' And Semester='" & Semester & "' And " & _
-
"(TimeStarted Between #" & TimeStarted & "# And #" & TimeFinished & "# Or " & _
-
"TimeFinished Between #" & TimeStarted & "# And #" & TimeFinished & "#))", _
-
dbConnection, 1, 1
-
-
'Checks if there is conflict
-
If adRecordset.RecordCount > 0 Then
-
Conflict = True
-
Else
-
Conflict = False
-
End If
-
-
Rey Sean
14 6868
Hello....
Could anyone help me this out?
I've just got back from vacation. Since nobody else seems to be helping, I'll try to have a look at it within the next day or two. If you like though, I can move it to the Access forum, where I think you'll find much more expertise with this kind of thing.
I've just got back from vacation. Since nobody else seems to be helping, I'll try to have a look at it within the next day or two. If you like though, I can move it to the Access forum, where I think you'll find much more expertise with this kind of thing.
Hi Killer42
Thanks for your reply and concern
Rey Sean
Just started looking into this now. It seems as though you'd simplify things somewhat if you use a unique character for each day. For instance... - Code Meaning
-
M Monday
-
T Tuesday
-
W Wednesday
-
R Thursday
-
F Friday
-
S Saturday
-
MR Monday & Thursday
-
TF Tuesday & Friday
-
WS Wednesday & Saturday
-
That way, you can easily detect a hit on say, Thursday, by checking if the day contains "R" ( Like "*R*"), regardless of what else is there.
QVeen72 1,445
Recognized Expert Top Contributor
Hi,
Change the Day Structure like as Killer Suggested..
And Change Your SQL Statement : -
adRecordset.Open "Select * From LoadSchedules Where " _
-
& " DayA='" & Day1 & "'" & _
-
" And Rooms.Title='" & Room _
-
& "' And Courses.Title='" & Course & "' And " & _
-
"Sections.Title='" & Section & "' And Semester='" & Semester & "' And " & _
-
" Day Like '*" & Day & "*' And ((" _
-
& TimeStarted & " Between TimeStarted And " & _
-
"TimeFinished) Or (" & TimeFinished & " Between TimeStarted And TimeFinished)) "
-
Regards
Veena
Hi Killer42
Hi Veena
I'm planning to display all the time which has no conflicts on a combo box and from there, the user can only selects the timeIN and TimeOUT and it would never prompt a conflict . Is it possible?
Rey Sean
Just started looking into this now. It seems as though you'd simplify things somewhat if you use a unique character for each day. For instance... - Code Meaning
-
M Monday
-
T Tuesday
-
W Wednesday
-
R Thursday
-
F Friday
-
S Saturday
-
MR Monday & Thursday
-
TF Tuesday & Friday
-
WS Wednesday & Saturday
-
That way, you can easily detect a hit on say, Thursday, by checking if the day contains "R" (Like "*R*"), regardless of what else is there.
Hi Killer42
I think this code applies only to a single day. How about the combination of days let us say Monday or Thursday (MR)?
For example:
If i have already a schedule on Thursday (R) and then I add a new schedule for Monday and Thursday (MR) same as records on thursday (rooms, subjects,...). How can you use *MR* to check R? This should prompt conflict.
QVeen72 1,445
Recognized Expert Top Contributor
Hi,
When You have Combination, Build the SQL Statement to Split and Check..
You need to Check for '*M*' As well As '*R*'
Though not a Very elegant Programming Practice, You can use ComboBox to give Time Selection..
How are you planning to Populate Combo...?
Is it "09:00", "09:30", "10:00"...? (Intervals of 30 mins..?)
What If the User want From "09:15"..?
Regards
Veena
Interval of 30 mins. Is it possible?
Rey Sean
QVeen72 1,445
Recognized Expert Top Contributor
Hi,
Yes, it is possible, -
Combo1.Clear
-
Dim i As Integer
-
Dim TDate As Date
-
TDate = 0
-
For i = 1 To 48
-
TDate = DateAdd("n", 30, TDate)
-
Combo1.AddItem Format(TDate, "hh:mm")
-
Next
-
Regards
Veena
Hi Veena
What I really meant was, what if i have this schedules in my records for tuesday (as for example). The minimum time is 7:00AM and the maximum time is 8:30PM. - TimeIN TimeOUT
-
7:00AM 8:30AM
-
10:00AM 1:00PM
-
4:00PM 7:00PM
-
Then the combobox must add this following items for TimeIN - TimeIN
-
8:30AM
-
9:00AM
-
9:30AM
-
1:00PM
-
1:30PM
-
2:00PM
-
2:30PM
-
3:00PM
-
3:30PM
-
7:00PM
-
7:30PM
-
Is i possible to remove the items that are conflicted? Hope you get what I really meant.
Rey Sean
When You have Combination, Build the SQL Statement to Split and Check..
You need to Check for '*M*' As well As '*R*'
Hi Veena
I'm not yet familiar with Split in SQL statement. Could you please show me how to this. Thanks.
Rey Sean
QVeen72 1,445
Recognized Expert Top Contributor
Hi,
Yes, it is possible
First Open a Recordset and Populate the Array with All the Booked Times, Say FArr(From Time array) and TArr(To Time Array)
Here, I'am populating with the Data Given by you..
Check this code: -
Combo1.Clear
-
Dim i As Integer
-
Dim TDate As Date
-
Dim AddFlag As Boolean
-
Dim j As Integer
-
'
-
Dim FArr(0 To 2) As Date
-
Dim TArr(0 To 2) As Date
-
FArr(0) = "07:00Am": TArr(0) = "08:30AM"
-
FArr(1) = "10:00AM": TArr(1) = "01:00PM"
-
FArr(2) = "04:00PM": TArr(2) = "07:00PM"
-
'
-
TDate = 0
-
For i = 1 To 48
-
TDate = DateAdd("n", 30, TDate)
-
AddFlag = True
-
For j = LBound(FArr) To UBound(FArr)
-
If Format(TDate, "hh:mmAM/PM") > FArr(j) And _
-
Format(TDate, "hh:mmAM/PM") < TArr(j) Then
-
AddFlag = False
-
Exit For
-
End If
-
Next
-
If AddFlag Then
-
Combo1.AddItem Format(TDate, "hh:mmAM/PM")
-
End If
-
Next
-
Run the Code, and Refine it you may need to check for >= and <=...
REgards
Veena
Hi Veena
I modified your codes: - Combo1.Clear
-
Dim i As Integer
-
Dim TDate As Date, MaxTime As Date 'VARIABLE ADDED
-
Dim AddFlag As Boolean
-
Dim j As Integer
-
'
-
Dim FArr(0 To 2) As Date
-
Dim TArr(0 To 2) As Date
-
FArr(0) = "07:00Am": TArr(0) = "08:30AM"
-
FArr(1) = "10:00AM": TArr(1) = "01:00PM"
-
FArr(2) = "04:00PM": TArr(2) = "07:00PM"
-
'
-
TDate = #7:00:00 AM#
-
MaxTime = #8:00:00 PM# 'ADDED
-
For i = 1 To 48
-
TDate = DateAdd("n", 30, TDate)
-
AddFlag = True
-
For j = LBound(FArr) To UBound(FArr)
-
If Format(TDate, "hh:mmAM/PM") >= FArr(j) And _ 'MODIFIED
-
Format(TDate, "hh:mmAM/PM") < TArr(j) Then
-
AddFlag = False
-
Exit For
-
End If
-
Next
-
-
If AddFlag Then
-
If TDate > MaxTime Then 'ADDED
-
Combo1.AddItem Format(TDate, "hh:mmAM/PM")
-
End If
-
End If
-
Next
Thanks for the codes Veena. A million thanks to you. : )
Now, my problem is how to connect it with the database record. I'll try do it. Good Luck to me.
Rey Sean
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Adisorn Ratanakovit |
last post by:
When you set up a full-text catalog in SQL Server and you set up the
population schedule, a job gets created and scheduled under SQL Server
Agent. The problem I encountered recently is when I...
|
by: Steve Cosh |
last post by:
Hi,
Im writting an asp app that tracks the users scores and info (its a
training app) to a access database, ive disabled the ie toolbars and
everthing so the user must use my nav buttons so i...
|
by: argniw |
last post by:
I have a schedule of annual events that need to occur in different
locations throughout the year. Each event has a due date associated
with it.
I also have an optimal schedule that consolidates...
|
by: greg7224 |
last post by:
I am currently working on a C# project that uses the Janus schedule
controls, and am having trouble getting it to print correctly in Day
view. The problem is that it will not print out the owners...
|
by: tstutting |
last post by:
Hello, This is my first post and I'd really appreciate any help I can get. Sorry this is so long but it's complicated. I'm a USAF Officer and I'm attempting to make a shared MS Access DB that...
| |
by: hgirma |
last post by:
Hello Gurus,
Is it possible to schedule a task to run an application deployed using
ClickOnce? The executable changes location with each update.. and if i
were to run the executable directly,...
|
by: lotus18 |
last post by:
Hello World
I have a problem in detecting the conflict schedule (Day and Time).
Day
1. M
2. T
3. W
4. TH
5. F
|
by: lotus18 |
last post by:
Hi
This is a follow-up post from my post (please click here) as CyberSoftHari suggested me to post it here.
These are the tables that I've made:
Schedules
-ScheduleID
-StartTime
|
by: Don |
last post by:
I wrote an app that alerts a user who attempts to open a file that the
file is currently in use. It works fine except when the file is
opened by Notepad. If a text file is opened, most computers...
|
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,...
|
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...
| |
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...
|
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...
|
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: 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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
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 ...
| |
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...
| |