Conflicting time for work schedule

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tamakm
    New Member
    • Jul 2013
    • 7

    Conflicting time for work schedule

    Hello,
    I have the ms access database which I use to assign overtime to employee.

    One tbl One 'Overtime Lines' Fields: Line No, Date, Start Time, End Time.

    Tbl Two 'Employee List' Fields: Employee name, Emp ID, Seniority No.

    Tbl three 'Overtime Signups Employee Name, Overtime Line number, Qualifications’ , Location
    Employee signup a week in advance by selecting overtime line number on line. Employees are allowed to signup all the lines. This line timings can be overlapping such as
    Start Time End Time
    0500 0900
    0600 1000
    0700 1000 etc.
    This can go to over 2000 records.
    We pull signup every Week and upload it to access Signup tbl.

    I have created a form to approve this overtime. We are only adding location (date, start time and end time is already pre populated) to mark as overtime is approved. using this form. (All the fields in the form are from same tbl)

    When approver of OT approves a slot by adding only location as approved (Start and End Time are pre populated in the form) , next time when approver approves another slot for the same employee by adding location, which is overlapping with previously approved line (Added Location).
    Problem I am facing is I am not entering Start and End time so can’t put the code to initiate the conflict message.
    Soon he / She enters the location.
    I want code or query to check current pre-populated Start time and End time with previous start and time for any conflict which is related to Location. If there is no conflict (No Record with location added) it should except the location, if there is a conflict I want to delete the location and pop the message that there is a conflict and goes to next record.
    Do I have to create new table? Because after all the overtime slots are approved. Query is generating approved OT in a PDF format report with Employee name, Date of OT he is approved and Time of OT he is approved for.
    So What I am looking for is What I can do from preventing user to add location if the previous time is conflicting with new approval. SO program should check five things, Employee, Date, Start Time, End Time, and Location is blank or not.

    I have added code in Query to check Start Time, EndTime, Employee Name, and Overtime line number by adding two copies of the same table. But it is not working because I already have the data in the table that is prepopulated in advance. so when I use this code in a form control to add record after just adding location it just comes up with the message because it is only checking for date time and employee name.
    I have been trying for long time and can't just let it go. Please help me understand and point me to right direcion.
    I will be greatful.
    Thank you,
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You need to show us the code you're using. And tell us what you mean by not working.

    Comment

    • Tamakm
      New Member
      • Jul 2013
      • 7

      #3
      I am not a programmer.

      Like access and create simple databases.

      I have this code in my query which I found on line.
      I have added this code in my query.
      I created a report from this query and added the report in form command button to give alert that there is a conflict.

      Soon I add location each and every approval that message comes up because all employees have signed up for overlapping overtime.

      So I think this can only work when you try to add new record. But My table already has all the record.

      The only thing I am doing is adding the location in the form that is based on this same table which has all the records including start and end time.

      I would appreciate your help

      Code:
      NoOTClash: 
      ([EqualizationToApproveAdvOT_1].[OT-StartTime]
            >=[EqualizationToApproveAdvOT].[OT-EndTime]) 
         Or ([EqualizationToApproveAdvOT_1].[OT-EndTime]
            <=[EqualizationToApproveAdvOT].[OT-StartTime])
         Or ([EqualizationToApproveAdvOT].[OfficersName]
            <>[EqualizationToApproveAdvOT_1].[OfficersName])
         Or ([EqualizationToApproveAdvOT].[OT_Date]
            <>[EqualizationToApproveAdvOT_1].[OT_Date]) 
         Or ([EqualizationToApproveAdvOT].[Overtime_lineNumber]
            =[EqualizationToApproveAdvOT_1].Overtime_lineNumber])
      Last edited by zmbd; Jul 6 '13, 07:23 PM. Reason: [Z{Please use the [CODE/] formatting button to format your posted code and SQL}{Stepped what appears to be calculated field for easier reading}][z{second edit... added white space to posting to ease t

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        Please provide the entire code...

        Post#1>...I have created a form to approve this overtime.
        Post#3>...I created a report from this query and added the report in form command button to give alert that there is a conflict.
        I suspect that you mean form and not report in your second post, yes? The two terms are NOT interchangable.

        We'll need the full code behind the control, not just the little snip-it:
        Open your form in design mode.
        Right click on the command button.
        In the pop-up menu, at the bottom, select properties.
        Select the "Events" tab.
        You will now see a listing of event triggers with names on the left side and and, if there is a code attached...
        In the "on click" you will see either [Event Procedure] or [Embedded Macro], if you do not see this please post back.
        In either case, click on the button that shows [...] in it:
        • In the case of the [Event Procedure], the VBA editor will open to the code related to the control. Please select the entire text, including the "Sub (name or your control)_click( ) thru and inculding "End Sub"
        • In the case of [Embedded Macro], the Macro editor will open. If you are using either Access V2007 or V2010, then you can <ctrlA>, <ctrlC> otherwise you will have to hand type the macro into a post.
        Now, in the reply box at the bottom here, FIRST click the [CODE/] button, this will insert "[code]..[/code]" between these two tags, you will either <ctrlV> to paste the copied text into the post, or where you will have to hand enter the macro code.
        Now you may submit the post.
        PLEASE, do NOT forget to enter your code between the two "[code]..[/code]" tags.
        Last edited by zmbd; Jul 6 '13, 07:54 PM.

        Comment

        • Tamakm
          New Member
          • Jul 2013
          • 7

          #5
          Apologize for posting code improperly. Actually, I have the query with the code listed previously With two copies of the table in that query. Than I created a report based on this query. and than created a form and added command button with the code below. But since I am not entering Date, StartTime, EndTime (Because this is already listed in the table. I just add a location for employee as I am approving the overtime. This code is not working. Thank You.

          Code:
           Public Function Check()
             Dim ApprovedOTLocation
             DoCmd.OpenReport "OTTimeConflictToApproveAdvOT", _
                acViewPreview
             Score = Reports![OTTimeConflictToApproveAdvOT].HasData
             DoCmd.Close acReport, "OTTimeConflictToApproveAdvOT"
             If Score = -1 Then
                MsgBox "There is a clash of Overtime Hours, Please try again."
             End If
          End Function
          Last edited by zmbd; Jul 7 '13, 06:06 AM. Reason: [Tamakm;{Try to add line Number}] [z{removed un-needed formating within the code block and reformatted}{the code block keeps collapsing... arrgh]

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            We would need to see the full SQL, not just the expression that was written.

            Comment

            • zmbd
              Recognized Expert Moderator Expert
              • Mar 2012
              • 5501

              #7
              No apology required. Happens quite frequently. :)

              A Function call is not normally what I would expect and would not norrmally be the code directly triggered via the command button. Please re-read my post and post the code for the command button too... if this is the VBA code, then there must be an [Embedded Macro] indicator in the control event code, we'll need to know that information.

              If I am reading your post correctly, you have a command button on your report that calls up the form?

              IF this is correct, you will have additional issues. I know that in a twitterpated moment, Microsoft tried adding interactivity to reports. This is fine until the user tries to modify the underlying record-set and it either crashes, causes an error, or just does nothing.

              It is best practice to keep in mind the following:
              • Forms are for interacting with the user.
              • Forms are for calling reports once the user has finished and needs a pretty picture for the customer (be that the boss or a client, doesn't matter)
              • Reports are for telling the user what happened or for creating that receipt for the client.

              Comment

              • Tamakm
                New Member
                • Jul 2013
                • 7

                #8
                CompletePicture of database

                Originally posted by Rabbit
                We would need to see the full SQL, not just the expression that was written.
                SQL below is in Access Query and Report is based on query which is run by function in the form command button.

                Code:
                NoOTClash:([EqualizationToApproveAdvOT_1].[OT-StartTime]>=[EqualizationToApproveAdvOT].[OT-EndTime]) 
                
                Or ([EqualizationToApproveAdvOT_1].[OT-EndTime]<=[EqualizationToApproveAdvOT].[OT-StartTime]) 
                
                Or ([EqualizationToApproveAdvOT].[OfficersName]<>[EqualizationToApproveAdvOT_1].[OfficersName]) 
                
                Or ([EqualizationToApproveAdvOT].[OT_Date]<>[EqualizationToApproveAdvOT_1].[OT_Date]) 
                
                Or ([EqualizationToApproveAdvOT].[ApprovedOTLocation]=" ")
                User only adds location as approved.
                once a location is assigned,
                when user comes accross same name with same date with overlapping start and End Time.
                Soon user adds location program should alert for overlapping of the shift that is approved previously.

                I got this code from one of the site.

                'Function below is in Form Command Button that is for Report I have created with Above query.
                The report has all the information except for Location which is the only thing user is adding as approved.

                Code:
                Public Function Check()
                Dim ApprovedOTLocation
                DoCmd.OpenReport "OTTimeConflictToApproveAdvOT", acViewPreview
                Score = Reports![OTTimeConflictToApproveAdvOT].HasData
                DoCmd.Close acReport, "OTTimeConflictToApproveAdvOT"
                If Score = -1 Then
                MsgBox "There is a clash of Overtime Hours, Please try again."
                End If
                End Function
                Attached Files

                Comment

                • Rabbit
                  Recognized Expert MVP
                  • Jan 2007
                  • 12517

                  #9
                  That's just the expression, where's the whole SQL command?

                  Comment

                  • Tamakm
                    New Member
                    • Jul 2013
                    • 7

                    #10
                    Originally posted by Rabbit
                    That's just the expression, where's the whole SQL command?
                    Top box in my reply is with SQL statement in my Query
                    and I am using that query in the report.
                    Not using other SQL cmmand for this. I have attached the table, Query and form.

                    Comment

                    • Rabbit
                      Recognized Expert MVP
                      • Jan 2007
                      • 12517

                      #11
                      No, that's not the full SQL, that's just an expression.

                      Comment

                      • Tamakm
                        New Member
                        • Jul 2013
                        • 7

                        #12
                        Originally posted by Rabbit
                        No, that's not the full SQL, that's just an expression.
                        Sorry, Didn't realised it. This is what you are looking to check?.

                        Code:
                        SELECT 
                          ([EqualizationToApproveAdvOT_1].[OT-StartTime]
                              >=[EqualizationToApproveAdvOT].[OT-EndTime]) 
                              Or ([EqualizationToApproveAdvOT_1].[OT-EndTime]
                              <=[EqualizationToApproveAdvOT].[OT-StartTime]) 
                              Or ([EqualizationToApproveAdvOT].[OfficersName]
                              <>[EqualizationToApproveAdvOT_1].[OfficersName]) 
                              Or ([EqualizationToApproveAdvOT].[OT_Date]
                              <>[EqualizationToApproveAdvOT_1].[OT_Date]) 
                              Or ([EqualizationToApproveAdvOT].[Overtime_lineNumber]
                              =[EqualizationToApproveAdvOT_1].[Overtime_lineNumber])
                              AS NoOTClash,
                           EqualizationToApproveAdvOT.OfficersName,
                           EqualizationToApproveAdvOT.Overtime_lineNumber,
                           EqualizationToApproveAdvOT.OT_PP,
                           EqualizationToApproveAdvOT.OT_PP_WeekNumber,
                           EqualizationToApproveAdvOT.OT_Date,
                           EqualizationToApproveAdvOT.[OT-StartTime],
                           EqualizationToApproveAdvOT.[OT-EndTime],
                           EqualizationToApproveAdvOT.TotalHoursOFOT,
                           EqualizationToApproveAdvOT.Qualifications, 
                           EqualizationToApproveAdvOT.TitleRank, 
                           EqualizationToApproveAdvOT.[SumOfSumOfTotal OT Hrs], 
                           EqualizationToApproveAdvOT.SeniorityRank, 
                           EqualizationToApproveAdvOT.ApprovedOTLocation, 
                           EqualizationToApproveAdvOT_1.OfficersName, 
                           EqualizationToApproveAdvOT_1.Overtime_lineNumber, 
                           EqualizationToApproveAdvOT_1.OT_PP, 
                           EqualizationToApproveAdvOT_1.OT_PP_WeekNumber, 
                           EqualizationToApproveAdvOT_1.OT_Date, 
                           EqualizationToApproveAdvOT_1.[OT-StartTime], 
                           EqualizationToApproveAdvOT_1.[OT-EndTime], 
                           EqualizationToApproveAdvOT_1.TotalHoursOFOT, 
                           EqualizationToApproveAdvOT_1.Qualifications, 
                           EqualizationToApproveAdvOT_1.TitleRank, 
                           EqualizationToApproveAdvOT_1.[SumOfSumOfTotal OT 
                           Hrs],
                           EqualizationToApproveAdvOT_1.SeniorityRank, 
                           EqualizationToApproveAdvOT_1.ApprovedOTLocation
                        FROM 
                           EqualizationToApproveAdvOT, 
                           EqualizationToApproveAdvOT 
                              AS EqualizationToApproveAdvOT_1
                        WHERE (
                           ((([EqualizationToApproveAdvOT_1].[OT-StartTime]
                              >=[EqualizationToApproveAdvOT].[OT-EndTime]) 
                           Or ([EqualizationToApproveAdvOT_1].[OT-EndTime]
                              <=[EqualizationToApproveAdvOT].[OT-StartTime]) 
                           Or ([EqualizationToApproveAdvOT].[OfficersName]
                              <>[EqualizationToApproveAdvOT_1].[OfficersName])
                           Or ([EqualizationToApproveAdvOT].[OT_Date]
                              <>[EqualizationToApproveAdvOT_1].[OT_Date]) 
                           Or ([EqualizationToApproveAdvOT].[Overtime_lineNumber]
                              =[EqualizationToApproveAdvOT_1].[Overtime_lineNumber]))
                           =False));
                        Last edited by zmbd; Aug 13 '13, 11:44 AM. Reason: [z{Removed unneeded list tags}{stepped SQL for better read}]

                        Comment

                        • Rabbit
                          Recognized Expert MVP
                          • Jan 2007
                          • 12517

                          #13
                          You shouldn't do a Cartesian product like that, it makes the where clause too complicated to work out. You need to first join the tables correctly and then use the where clause to look for overlap only, not to simulate your join.

                          Comment

                          • Tamakm
                            New Member
                            • Jul 2013
                            • 7

                            #14
                            Originally posted by Rabbit
                            You shouldn't do a Cartesian product like that, it makes the where clause too complicated to work out. You need to first join the tables correctly and then use the where clause to look for overlap only, not to simulate your join.
                            Thank you for taking time to respond. I was really looking for help and understanding to write the code.

                            Comment

                            • Rabbit
                              Recognized Expert MVP
                              • Jan 2007
                              • 12517

                              #15
                              If there's something you don't understand in what I said, tell me which part and I'll explain it.

                              Comment

                              Working...