473,508 Members | 4,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Requery causing duplicate table entry

25 New Member
I'm creating a scheduling application for a hospital department that indicates when they've exceeded the minimum required staff for a particular shift. I have a table keeping track of the count and another table that contains the miniumum values based on specific shifts and roles. For example, I know the exact number of staff needed at 2 AM, and I have a staff member working from 11PM through 7AM so I need to indicate that this person will fulfill one of the required slots at 2AM. I also need to account for staff carrying over into a different day, as indicated in this example, so I have to create counts for multiple days (as in day before scheduled date or day after scheduled date). I need to provide this information for multiple days. When I created the information for the initial day, I started getting the non-descript "Microsoft Access has encountered a problem and needs to close. We are sorry for the inconvenience." I embedded a requery command in the code and it all functions correctly for the first day. When I try and enter information on subsequent days, I get an error that the requery command is creating a duplicate entry in the database. Since this code finds current entries for a role and a shift then adds one to the count, I don't understand how it could be creating duplicate values. Here's the vb code for the module:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. 'OpenArgs:=Me.ScheduleDate & "|" & Me.StaffRole & "|" & Me.StaffShift
  3. Private Sub Form_Load()
  4. DoCmd.Requery
  5. Dim TempRole As Integer
  6. Dim strSQL As String
  7. Dim i As Integer
  8. Dim j As Integer
  9. Dim k As Integer
  10. Dim varSplit As Variant
  11. Dim FinalLoop, LoopCount, TempAMG, TempARN, TempCAR, TempCCA, TempCRN, TempEDU, TempEMT, TempIT, TempLPN, TempMGR, TempPRR, TempRN, TempUC As Integer
  12. Dim Starting As String
  13. Dim OriginalDate As Date
  14. Dim tsd As Date
  15. Dim OriginalDatePlusOne As Date
  16. If Me.OpenArgs <> vbNullString Then
  17.     varSplit = Split(Me.OpenArgs, "|")
  18.     OriginalDate = varSplit(0)
  19.     OriginalDatePlusOne = DateAdd("D", 1, varSplit(0))
  20.     TempRole = varSplit(1)
  21. End If
  22. 'if schedule date exists
  23. If DCount("[ScheduleDate]", "CoreScheduleCountOfPosition", "[ScheduleDate] = #" & OriginalDate & "#") Then
  24.     Me.ScheduleDate = varSplit(0)
  25.     tsd = DateAdd("d", 1, OriginalDate)
  26.  
  27. 'if schedule date + 1 exists
  28.     If DCount("[ScheduleDate]", "CoreScheduleCountOfPosition", "[ScheduleDate] = #" & tsd & "#") Then
  29.         FinalLoop = DLookup("Duration", "ListOfShifts", "ID =" & varSplit(2)) + 1
  30.         Starting = DLookup("StartTime", "ListOfShifts", "ID =" & varSplit(2))
  31.         DoCmd.Requery
  32.         Me.Recordset.FindFirst "[ScheduleDate] = #" & OriginalDate & "# and [TimeSlot] = '" & Starting & "'"
  33. '    End If
  34. 'update loop
  35.         For LoopCount = 1 To FinalLoop
  36.             Call Initialize
  37.             If TempRole = 1 Then
  38.                 Me.ManagerCount = TempMGR + 1
  39.             End If
  40.             If TempRole = 2 Then
  41.                 Me.AsstManagerCount = TempAMG + 1
  42.             End If
  43.             If TempRole = 3 Then
  44.                 Me.EducCount = TempEDU + 1
  45.             End If
  46.             If TempRole = 4 Then
  47.                 Me.ITCount = TempIT + 1
  48.             End If
  49.             If TempRole = 5 Then
  50.                 Me.PRRCount = TempPRR + 1
  51.             End If
  52.             If TempRole = 6 Then
  53.                 Me.CARCount = TempCAR + 1
  54.             End If
  55.             If TempRole = 7 Then
  56.                 Me.ARNCount = TempARN + 1
  57.             End If
  58.             If TempRole = 8 Then
  59.                 Me.CRNCount = TempARN + 1
  60.             End If
  61.             If TempRole = 9 Then
  62.                 Me.RNCount = TempRN + 1
  63.             End If
  64.             If TempRole = 10 Then
  65.                 Me.LPNCount = TempLPN + 1
  66.             End If
  67.             If TempRole = 11 Then
  68.                 Me.EMTCount = TempEMT + 1
  69.             End If
  70.             If TempRole = 12 Then
  71.                 Me.UCCount = TempUC + 1
  72.             End If
  73.             If TempRole = 13 Then
  74.                 Me.CCACount = TempCCA + 1
  75.             End If
  76.             Me.CSCStatus = "W"
  77.             If LoopCount <= FinalLoop Then
  78.                 DoCmd.GoToRecord , , acNext
  79.             End If
  80.         Next LoopCount
  81.         Else:
  82.  
  83. 'create and update second set if it doesn't exist
  84.             Dim tc As Integer
  85.             For k = 1 To 24
  86.                     If k >= 1 And k <= 10 Then
  87.                         Me.TimeSlot = "0" & k - 1 & ":00"
  88.                     Else:
  89.                         Me.TimeSlot = k - 1 & ":00"
  90.                     End If
  91.                 Me.ScheduleDate = tsd
  92.                 Call SetToZero
  93.                 Me.CSCStatus = "W"
  94.                 If k <= 24 Then
  95.                     DoCmd.GoToRecord , , acNewRec
  96.                 End If
  97.             Next k
  98.         FinalLoop = DLookup("Duration", "ListOfShifts", "ID =" & varSplit(2)) + 1
  99.         Starting = DLookup("StartTime", "ListOfShifts", "ID =" & varSplit(2))
  100.         Me.Recordset.FindFirst "[ScheduleDate] = #" & varSplit(0) & "# and [TimeSlot] = '" & Starting & "'"
  101.         For LoopCount = 1 To FinalLoop
  102.             Call Initialize
  103.             If TempRole = 1 Then
  104.                 Me.ManagerCount = TempMGR + 1
  105.             End If
  106.             If TempRole = 2 Then
  107.                 Me.AsstManagerCount = TempAMG + 1
  108.             End If
  109.             If TempRole = 3 Then
  110.                 Me.EducCount = TempEDU + 1
  111.             End If
  112.             If TempRole = 4 Then
  113.                 Me.ITCount = TempIT + 1
  114.             End If
  115.             If TempRole = 5 Then
  116.                 Me.PRRCount = TempPRR + 1
  117.             End If
  118.             If TempRole = 6 Then
  119.                 Me.CARCount = TempCAR + 1
  120.             End If
  121.             If TempRole = 7 Then
  122.                 Me.ARNCount = TempARN + 1
  123.             End If
  124.             If TempRole = 8 Then
  125.                 Me.CRNCount = TempARN + 1
  126.             End If
  127.             If TempRole = 9 Then
  128.                 Me.RNCount = TempRN + 1
  129.             End If
  130.             If TempRole = 10 Then
  131.                 Me.LPNCount = TempLPN + 1
  132.             End If
  133.             If TempRole = 11 Then
  134.                 Me.EMTCount = TempEMT + 1
  135.             End If
  136.             If TempRole = 12 Then
  137.                 Me.UCCount = TempUC + 1
  138.             End If
  139.             If TempRole = 13 Then
  140.                 Me.CCACount = TempCCA + 1
  141.             End If
  142.             Me.CSCStatus = "W"
  143.             If LoopCount <= FinalLoop Then
  144.                 DoCmd.GoToRecord , , acNext
  145.             End If
  146.         Next LoopCount
  147.         End If
  148.     Else:
  149.  
  150. 'create if second exists but first doesn't
  151.     DoCmd.GoToRecord , , acNewRec
  152.         If DCount("[ScheduleDate]", "CoreScheduleCountOfPosition", "[ScheduleDate] = #" & OriginalDatePlusOne & "#") Then
  153.            For i = 1 To 24
  154.                 Me.ScheduleDate = OriginalDate
  155.                 If i >= 1 And i <= 10 Then
  156.                     Me.TimeSlot = "0" & (i - 1) & ":00"
  157.                 Else:
  158.                     Me.TimeSlot = (i - 1) & ":00"
  159.                 End If
  160.                 Call SetToZero
  161.                 Me.CSCStatus = "W"
  162.                 If i <= 24 Then
  163.                     DoCmd.GoToRecord , , acNewRec
  164.                 End If
  165.             Next i
  166.             FinalLoop = DLookup("Duration", "ListOfShifts", "ID =" & varSplit(2)) + 1
  167.             Starting = DLookup("StartTime", "ListOfShifts", "ID =" & varSplit(2))
  168.             Me.Recordset.FindFirst "[ScheduleDate] = #" & varSplit(0) & "# and [TimeSlot] = '" & Starting & "'"
  169.             For LoopCount = 1 To FinalLoop
  170.                 Call Initialize
  171.                 If TempRole = 1 Then
  172.                     Me.ManagerCount = TempMGR + 1
  173.                 End If
  174.                 If TempRole = 2 Then
  175.                     Me.AsstManagerCount = TempAMG + 1
  176.                 End If
  177.                 If TempRole = 3 Then
  178.                     Me.EducCount = TempEDU + 1
  179.                 End If
  180.                 If TempRole = 4 Then
  181.                     Me.ITCount = TempIT + 1
  182.                 End If
  183.                 If TempRole = 5 Then
  184.                     Me.PRRCount = TempPRR + 1
  185.                 End If
  186.                 If TempRole = 6 Then
  187.                     Me.CARCount = TempCAR + 1
  188.                 End If
  189.                 If TempRole = 7 Then
  190.                     Me.ARNCount = TempARN + 1
  191.                 End If
  192.                 If TempRole = 8 Then
  193.                     Me.CRNCount = TempARN + 1
  194.                 End If
  195.                 If TempRole = 9 Then
  196.                     Me.RNCount = TempRN + 1
  197.                 End If
  198.                 If TempRole = 10 Then
  199.                     Me.LPNCount = TempLPN + 1
  200.                 End If
  201.                 If TempRole = 11 Then
  202.                     Me.EMTCount = TempEMT + 1
  203.                 End If
  204.                 If TempRole = 12 Then
  205.                     Me.UCCount = TempUC + 1
  206.                 End If
  207.                 If TempRole = 13 Then
  208.                     Me.CCACount = TempCCA + 1
  209.                 End If
  210.                 Me.CSCStatus = "W"
  211.                 If LoopCount <= FinalLoop Then
  212.                     If Me.TimeSlot = "23:00" Then
  213.                         Me.Recordset.FindFirst "[ScheduleDate] = #" & OriginalDatePlusOne & "# and [TimeSlot] = '00:00'"
  214.                     Else:
  215.                         DoCmd.GoToRecord , , acNext
  216.                     End If
  217.                 End If
  218.             Next LoopCount
  219.         Else:
  220.  
  221. 'create both sets if neither exists
  222.             For i = 1 To 24
  223.                 Me.ScheduleDate = OriginalDate
  224.                 If i >= 1 And i <= 10 Then
  225.                     Me.TimeSlot = "0" & (i - 1) & ":00"
  226.                 Else:
  227.                     Me.TimeSlot = (i - 1) & ":00"
  228.                 End If
  229.                 Call SetToZero
  230.                 If i <= 24 Then
  231.                     DoCmd.GoToRecord , , acNewRec
  232.                 End If
  233.             Next i
  234.             For i = 1 To 24
  235.                 Me.ScheduleDate = OriginalDatePlusOne
  236.                 If i >= 1 And i <= 10 Then
  237.                     Me.TimeSlot = "0" & (i - 1) & ":00"
  238.                 Else:
  239.                     Me.TimeSlot = (i - 1) & ":00"
  240.                 End If
  241.                 Call SetToZero
  242.                 Me.CSCStatus = "W"
  243.                 If i <= 24 Then
  244.                     DoCmd.GoToRecord , , acNewRec
  245.                 End If
  246.             Next i
  247.  
  248.             FinalLoop = DLookup("Duration", "ListOfShifts", "ID =" & varSplit(2)) + 1
  249.             Starting = DLookup("StartTime", "ListOfShifts", "ID =" & varSplit(2))
  250.             Me.Recordset.FindFirst "[ScheduleDate] = #" & varSplit(0) & "# and [TimeSlot] = '" & Starting & "'"
  251.             For LoopCount = 1 To FinalLoop
  252.                 Call Initialize
  253.                 If TempRole = 1 Then
  254.                     Me.ManagerCount = TempMGR + 1
  255.                 End If
  256.                 If TempRole = 2 Then
  257.                     Me.AsstManagerCount = TempAMG + 1
  258.                 End If
  259.                 If TempRole = 3 Then
  260.                     Me.EducCount = TempEDU + 1
  261.                 End If
  262.                 If TempRole = 4 Then
  263.                     Me.ITCount = TempIT + 1
  264.                 End If
  265.                 If TempRole = 5 Then
  266.                     Me.PRRCount = TempPRR + 1
  267.                 End If
  268.                 If TempRole = 6 Then
  269.                     Me.CARCount = TempCAR + 1
  270.                 End If
  271.                 If TempRole = 7 Then
  272.                     Me.ARNCount = TempARN + 1
  273.                 End If
  274.                 If TempRole = 8 Then
  275.                     Me.CRNCount = TempARN + 1
  276.                 End If
  277.                 If TempRole = 9 Then
  278.                     Me.RNCount = TempRN + 1
  279.                 End If
  280.                 If TempRole = 10 Then
  281.                     Me.LPNCount = TempLPN + 1
  282.                 End If
  283.                 If TempRole = 11 Then
  284.                     Me.EMTCount = TempEMT + 1
  285.                 End If
  286.                 If TempRole = 12 Then
  287.                     Me.UCCount = TempUC + 1
  288.                 End If
  289.                 If TempRole = 13 Then
  290.                     Me.CCACount = TempCCA + 1
  291.                 End If
  292.                 Me.CSCStatus = "W"
  293.                 If LoopCount <= FinalLoop Then
  294.                     DoCmd.GoToRecord , , acNext
  295.                 End If
  296.             Next LoopCount
  297.         End If
  298.     End If
  299. 'End If
  300. DoCmd.Requery
  301. DoCmd.Close acForm, "BuildScheduleCount2"
  302. End Sub
  303.  
  304. Public Sub Initialize()
  305.             TempAMG = Me.AsstManagerCount
  306.             TempARN = Me.ARNCount
  307.             TempCAR = Me.CARCount
  308.             TempCCA = Me.CCACount
  309.             TempCRN = Me.CRNCount
  310.             TempEDU = Me.EducCount
  311.             TempEMT = Me.EMTCount
  312.             TempIT = Me.ITCount
  313.             TempLPN = Me.LPNCount
  314.             TempMGR = Me.ManagerCount
  315.             TempPRR = Me.PRRCount
  316.             TempRN = Me.RNCount
  317.             TempUC = Me.UCCount
  318. End Sub
  319.  
  320. Public Sub SetToZero()
  321.                 Me.ManagerCount = 0
  322.                 Me.AsstManagerCount = 0
  323.                 Me.EducCount = 0
  324.                 Me.ITCount = 0
  325.                 Me.PRRCount = 0
  326.                 Me.CARCount = 0
  327.                 Me.ARNCount = 0
  328.                 Me.CRNCount = 0
  329.                 Me.RNCount = 0
  330.                 Me.LPNCount = 0
  331.                 Me.EMTCount = 0
  332.                 Me.UCCount = 0
  333.                 Me.CCACount = 0
  334. End Sub
  335.  
Any assistance with this would be greatly appreciated!

Thanks
Dec 24 '12 #1
24 3533
zmbd
5,501 Recognized Expert Moderator Expert
While I take a second to digest your code please do the following steps:

[Z{Edit} What version of Access are you using? From line 11 it appears that you are using one of the older versions as in 2003 the single line "dim (muli varible) as type" was discouraged and in 2007/2010 will cause you issues. You should go back and change anything looking like:
Dim FinalLoop, LoopCount, TempAMG As Integer
to
Dim FinalLoop As Integer, LoopCount As Integer, TempAMG As Integer
This way when you upgrade you wont run into the typecasting issue.{/edit}]


Please go to your vba editor in MS Access
Then go to the Ribbon/toolbar:> Tools :> Options
Editor tab:
Uncheck "Auto Syntax Check" all this does is add an annoying pop-up that says... you goofed... click ok... the line will already turn red when you mis-form the code.

Check Mark "Require Variable Declaration" (this will place the option explicate at the top of every new code module)
checkmark all of the remaining options.

I like an auto indent of 4; however, I wouldn't go less than 3 or more than 5 just as a personal preference.
The remaining stuff can be left as default.

Now go thru all of your form modules, standard modules, and class modules and make sure that the following two lines are the VERY first two lines in every one of these modules

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database 
  2. Option Explicit 
Now compile your project.
Fix any errors
Re-compile your project
Repeat the above three lines until you can compile the project without an error

If you do find and correct any errors, we'll need to see the new code.
Dec 24 '12 #2
Rabbit
12,516 Recognized Expert Moderator MVP
This is only from a cursory glance.

1) On line 95, 151, 163, 231, 244 and you are creating new records. That's your most likely cause of duplicates.

2) Your database design looks unnormalized.

3) You are probably making this much more complicated than it needs to be with all that code. If you have all the necessary data in the tables, all you need is a single query to check whether or not a time frame is covered.
Dec 24 '12 #3
zmbd
5,501 Recognized Expert Moderator Expert
Please list the relavent tables as follows:

Tablename
[fieldname] (type) (key/index) (relationships)

Example:
tbl_A
[A_pk] (autonumber)(PrimaryKey)
[A_fk_B] (long)(foriegn key 1 to Many with tbl_b)(required, no nulls)
[A_field1] (text(25))

tbl_B
[B_pk] (autonumber)(PrimaryKey)(B_1:m_with tbl_a)
[B_fk_C] (long)(foriegn key 1 to Many with tbl_C)(required, no nulls)
[B_field1] (text(25)) Required, no nulls, indexed no duplicates
[B_field2] (long)

Example data would help... just a few records

If needed for privacy
Names can be changed to "John Doe" and "Jane Doe" etc...
Phone numbers to (123)555-0001, (123)555-0002 etc...
Same thing with SSN

I don't need every table, just the ones that feed the form and feed each other.

I don't need every record, just an example or three so long as they reflect the overall data.

-
Why I'm asking is that it appears that you have hard coded a lot of your roles and other information and then are trying hand-bash your human resources against these hardcoded slots to get your counts. This is the source of your issues.

Depending on how your tables are setup, you may be able to do this with a crosstab query and may not need any VBA or at least will be able to cut your code to a smaller and more comprehensible set.
-

I realize that once you've put so much effort into doing the project it's somewhat daunting to have feedback that says...
"there's maybe a better way." Please don't take this as personal comment on your abilities - but as one peer to another in the spirit of a helping hand.

I would highly recommend that you go ahead and read thru the following two links... I have an suspicion that you'll find them useful:
A Tutorial for Access
Database Normalization and Table Structures.
Dec 24 '12 #4
MLEBL
25 New Member
Rabbit Responses:
1) the process works fine when I'm modifying the intial date, it's only when I move over to a subsequent date that I get the duplicate error.
2) in what sense? I have created several tables to minimize the amount of data that will be stored in the scheduling table (so instead of name, role, shift, ... being stored each time someone is scheduled, it only has to store the appropriate mapped key integer).
3) UNDERSTATEMENT! This thing is SOOO complex. I suppose I could create an update query that replaces the logic for incrementing the values in the count to simplify this section.

BTW, thanks for the help back in November . . . I warned you I'd be back!
Dec 24 '12 #5
MLEBL
25 New Member
zmbd response:
I tried making the changes you suggested and get the same errors. I'm running 2010 (code identified was probably a format I utilized from reviewing old Access suggestions). The only problem is that I started running into problems in my public sub module for Initialize saying that it couldn't find the variables. I've embedded the Dim statement into the sub module to get this working. It still works fine on the first day of scheduling but gives me the duplicate error on subsequent days. I've confirmed that the values I'm pushing are the appropriate values for the date I'm updating. Based on the point in the vb code where I get the error, it's identifying the date/role/shift as existing so it shouldn't be creating a new value. Would you be open to a participating in a webex so you can see this monster first hand. I believe that I've created my tables appropriately based on the functionality that I'm trying to create.
Dec 24 '12 #6
zmbd
5,501 Recognized Expert Moderator Expert
Rabbit, looks like I cross posted with you!

I just found those same lines... I had to step out after my last post asking for the tables.... hydrogen leak inside one of my instruments. A very bad thing... easy fix... just bad thing.

MLEBL, you did warn us. :)
Tables please.
You shouldn't need any maketable or other things... I think once we see the DB structure the solution will present itself quite nicely. I have faith in Rabbit My SQL master, or perhaps this padawan will be able to find the solution. :)

Sorry, at work pc... webex is barred.
Dec 24 '12 #7
Rabbit
12,516 Recognized Expert Moderator MVP
1) Again, it was only a cursory glance. But the fact that you are creating records each time it is run is probably the cause of the errors. So that's where you need to start investigating. You need to look at how it's creating those records and what it's putting into those records so that can figure out where it's causing the duplication.

2) You haven't posted your table structure so I can only make inferences about the design. The reason it looks like unnormalized is because you have fields like this: ManagerCount, ITCount, CARCount, etc. On the face of it, having multiple fields for different counts is unnormalized.

3) I don't have the time right now to get into this point but I will come back to it later today. I really do think you are overcomplicating the solution.
Dec 24 '12 #8
MLEBL
25 New Member
Here's the breakdown of the relevent tables:

Table CoreSchedule
DateTime Date/Time
ScheduleDate Date/Time Primary Key
StaffMember Number Primary Key (1:1 staff table)
StaffShift Number Primary Key (1:1 ListOfShifts table)
StaffRole Number lookup in ListOfPostiion table
Status Text Primary Key ("W"-working, "F"-final)
StaffShiftStart Date/Time
StaffShiftEnd Date/Time

Table CoreScheduleCountOfPosition
ScheduleDate Date/Time Primary Key
TimeSlot Text Primary Key
ManagerCount Number
AsstManagerCount Number
EducCount Number
ITCount Number
PRRCount Number
CARCount Number
ARNCount Number
CRNCount Number
RNCount Number
LPNCount Number
EMTCount Number
UCCount Number
CCACount Number
CSCStatus Text

Table ListOfPosition
ID AutoNumber Primary Key
Position Text

Table ListOfShifts
ID AutoNumber Primary Key
ShiftDescription Text
StartTime Text
EndTime Text
Duration Number

Table Staff
ID AutoNumber Primary Key
StaffName Text
Role Number Lookup in ListOfStaffRole
PreferredArea Number Lookup in ListOfAreas
PrimaryContactNumber Text
FTEStatus Number Lookup in ListOfFTE
PreferredShift Number Lookup in ListOfPreferredShift
PreferredHours Number Lookup in ListOfPreferredHours
HireDate Date/Time
DeployDate Date/Time
Agency Yes/No
Traveler Yes/No
ActiveStatus Yes/No
DistantEmployee Yes/No
Wave Number Lookup in Wave
Dec 24 '12 #9
Rabbit
12,516 Recognized Expert Moderator MVP
I still don't have the time right now to go into the SQL solution but a quick note on the design. Most of it looks normalized except for CoreScheduleCountOfPosition.

The structure should be:
ScheduleDate Date/Time
TimeSlot Text
Position Text
StaffNeeded Number

The reason you would want to normalize down to this level is for future changes. If you add a new position to your old design, you would have to change the design of the table and update all your queries, reports, and forms. Whereas the normalized design only requires adding a row into that table. Everything else will handle itself.

When I get more time, I will go into the SQL solution.
Dec 24 '12 #10
NeoPa
32,557 Recognized Expert Moderator MVP
Looking through the other comments briefly, it seems they cover the same sort of comments I am thinking of. You should not be considering storing half the information you are storing, but query it from the existing data. The db design is the most important aspect of any project and Normalisation should be the basis of any design. The more complex the design, the more important the Normalisation rules are. There is already a link to the article that I would like to draw your attention to. Please read it. Without that understanding it will be very difficult to make any progress on this project at all.

One point I would raise though, is that finding overlapping dates (or timestamps) is another fundamental of a project such as this. You may find some interesting points on the fundamentals of this in Time Interval Overlapping (MS Access 2003).
Dec 24 '12 #11
MLEBL
25 New Member
I started out normalizing to this level, but due to client requirements I couldn't figure out how to incorporate this into the design. The requirement is that the manager creates the required staffing numbers for each hour and each position in a spreadsheet design via this Access tool. The count table refers back to the requirements table to make sure that all appropriate positions are filled. This whole thing is easier to show than to explain, so maybe when you get some time I can establish a webex to show you how this works. I only have test staff in the table currently (Micky Mouse . . . etc), so it wouldn't be a problem showing you the database and contents.
Dec 24 '12 #12
NeoPa
32,557 Recognized Expert Moderator MVP
I mean no disrespect, but if you're still thinking in terms of continuing with what you have already, I see no reason to believe that you could explain your situation clearly and succinctly even with a webex session, which would involve a level of time commitment on one of our parts. I see no signs of you having a clear enough appreciation of your own situation even, let alone the clarity to explain to people who all know better anyway (and have been trying to impart to you the results of their experience). It's possible I'm wrong, I suppose, but I'm not planning to spend a fair bit of time proving something I'm already reasonably certain of, to someone who isn't happy to accept advice after they've asked for it. Even when three separate and experienced helpers have all come on here and replied with the same basic advice.

I sympathise with you for the hole you've got yourself into, but until you stop digging there's little we can say to help anyway.
Dec 24 '12 #13
MLEBL
25 New Member
You may not have meant it, but it comes off as completely disrespectful. I've indicated that I initially started down the road indicated by all three experts only to have been derailed by the client's requests. My lack of experience with Access is probably the root of the issue, but I still don't see where you've provided direction to assist (only pointing to online articles on database normality). If you read Rabbit's post, all of my tables appear to be normailzed with the exception of the CoreScheduleCountOfPosition which I explained has to refer back to a detailed list of expected staffing counts created by the client. I suppose I'll have to continue muddling through this on my own.
Dec 24 '12 #14
zmbd
5,501 Recognized Expert Moderator Expert
MLEBL:
whew... take a deep breath.
Give Rabbit and myself a chance to take a look here too.

We all understand that occasionally the end-user doesn't have the greatest idea or has a perceived need that we have to work with/around or teach them that there is a better way to do the task. Hopefully once we’ve hit things with a hammer or two, you’ll have a tool to work with to train the user.

I’ll also make note that you did not tell us until post #12 that table CoreScheduleCountOfPosition is a workaround for a customer requirement. It would have been most helpful to know that when you posted the table outline. We can only work with what you give us. Thus, I surmise Neopa’s frustration with the apparent lack of interest on your part in what we’ve suggested so far.

Now. If you look at when I posted the links all you had posted was code; that in itself has a few issues, and even then I could tell that there was some issue with the design of the database; however, without the tables I couldn’t even begin to help you unless I tried to build a database myself to solve your project. Something I just don’t have the time today to do.

Going back to the your tables that I asked for to confirm what I had suspected in that your database was not truly normalized. In that Rabbit found even one table that is not normalized, then by definition, makes the entire database non-normalized. HOWEVER, Master-Rabbit stated that there might be a SQL solution to your quandary; thus, all is not lost.

So, once again, please take a deep breath and let’s continue to work thru this.

As you can already see, providing little details like customer requirements will help us to understand what you’re after; therefor, if there are any more such tidbits you would like to share, now is the time do so.

As for the webex session… as I told you in my earlier post, My IT blocks all such third party services so you’re out of luck on that part from me. They even block skype and magic jack!

Anyway back to the lab to put out another issue. Shame I had to spend the time trying to calm people down here and in lab instead of doing the fun stuff in either place. Sigh
v:-(
Dec 24 '12 #15
NeoPa
32,557 Recognized Expert Moderator MVP
I've tried to say it how it is. There is no intent to show disrespect, however, I'd be dishonest if I failed to say that I believe you are coming at this the wrong way, and your approach to the advice given, by all three experts, is unresponsive. Your post #12 seems to indicate that you believe, contrary to what you've been told by those that you have asked for help, that your way makes better sense. In such circumstances, it certainly doesn't make good sense to me to spend time sharing a webex session with you. I don't believe you have anything to teach me, from what I've read so far, and you seem quite unwilling to listen to what we say. I believe that, to make progress, you must at least start from an understanding that your first, and most important, task is to get the design for the project normalised. I've tried to express this position, as I don't believe anyone benefits from beating around the bush. In life, and especially in technical discussions, the truth is of the utmost importance to express. If people's feelings are hurt by the truth then I rarely believe the problem is with the truth. Please feel free to ignore what I post if that suits you better. I will continue to express the truth to the best of my understanding and ability.

PS. Clearly this is my personal view and, though I am a moderator, is not necessarily the view of the site on this occasion, nor of other experts. I'm sure Z & Rabbit will be happy to express their positions for themselves.
Dec 24 '12 #16
MLEBL
25 New Member
Thanks zmdb!

Here's all of the expectations and requirements:
1) Create an application where all staff members can be identified with their preferred location for work (since there are multiple departments within the primary location), preferred shift (morning, evening, night, or rotating), preferred hours (4, 8, or 12 hour shifts preferred), FTE status (as a decimal), active indicator, contract indicator, traveler indicator (with contract dates), extended travel time indicator (for staff living outside of the metro area), primary position (four identified for this particular department, and if the selected position is "RN", then track compliance dates for several required compliancies; if any other position, then track compliance date for CPR certification).
2) Provide a tool where the core staffing requirements can be identified by position and hour for a 24 hour period to include anticipated customer volume. Report the staff:customer ratio based on the number of customers expected at each hour and total for the day (total staff:customer).
3) Provide a tool where a two-week core schedule can be created in a list layout; list each staff member and allow the staffing manager to select the appropriate shift and role for each staff member. Must provide full two weeks while building to allow the builder to see what is currently scheduled, and it must compare the hourly schedule to the minimum staff requirements for each hour established in requirement #2 . . . and keep versioning as per state requirements.
4) Option: provide visual representation of daily requirements against daily schedule
5) Track compliancies. Build report indicating staff members whose compliancies are expiring within the next 30 days.
6) Build a variety of schedule reports (schedule for one particular staff member, daily schedule with all staff members, schedule by week (for one, two, four, or six week intervals) built as a table with each row indicating the staff member and each column as the scheduled date with the cell value indicating the shift for that staff member.
7) Build a position control report based on staffing positions approved and filled. For example, if the department is approved for 20 RNs and only 18 are hired, then the report must identify the 18 hired plus two blank lines indicating the shortage.
8) When selecting a staff member within the core schedule or daily schedule to work a shift, it cannot be 8 hours after or 8 hours before a previously scheduled shift.
9) after creating the core schedule, provide the scheduling manager with the ability to push the core schedule out for x number of bi-weekly iterations.

I think there's more, but this is what I'm tasked with completing. I've got almost two months invested currently and have most of the functionality working (or at least portions). I apologize for not providing all of the information up front, I just thought this might be a simple fix as I was just trying to figure out why a requery command would throw a "duplicate entry" error. I'm open to redesigning the entire database, but only if it will provide a fix to my issue and still meet the functionality requirements.

Thanks again, and I'm sorry for being such a pain!
Dec 24 '12 #17
MLEBL
25 New Member
Neopa, thanks for your honesty. I appreciate the feedback, but I'll look to Z or Rabbit for direction.
Dec 24 '12 #18
MLEBL
25 New Member
Thanks for the info! I looked through the templates and found nice examples of what I'd like my reports to look like (from the Excel samples), but there's only one Access entry from the grouping you suggested, and when I try to download it says "Template 'TimeCard.accdt' could not be instantiated. The Table 'Work Codes' could not be read from the template file. The object may be in an unrecognized format or contain invalid data."

I did find a resource scheduling database from 2003 that may contain some helpful information, so I'll give it a try to see if I can scavenge something from it. Have fun with in the lab and try not to blow up or burn down anything! Happy holidays!
Dec 24 '12 #19
Rabbit
12,516 Recognized Expert Moderator MVP
Just a few notes about the normalization before I get into the SQL.

While I said the count table was unnormalized. I also said it "looks like", the implication being that I did not have a lot of time to look at it. Also, since I don't actually know the purpose of all the fields, I can't make any concise statements about the rest of the design.

For example, the list of shift table has a field named Duration. It looks like a field whose value would be derived from the other fields in the table. Therefore, storing that value also breaks normalization.

Now for the SQL. This will be a simplified example of what you will eventually need. But it shows the crux of the solution. We can work towards building in the different complexities present in your design and requirements but this is the basis.

If I understand your requirements correctly, you basically have a table of start and end date times. You need to know if a target date time have enough records that overlap that target date time. The SQL for that is this:

Expand|Select|Wrap|Line Numbers
  1. SELECT count(*)
  2. FROM someTable
  3. WHERE #01/01/2012 01:00:00 PM# BETWEEN 
  4.    startDateTime and endDateTime
This simple query gives you a count of rows that overlap the target date time. If you have a table of target date times and grouping fields, then it's a simple matter of joining to that table, replacing the hard coded value with a field, and bringing in your grouping fields.

Unless the requirements are significantly more complex than this scenario, there's no need for all that code. But most any other requirements you need can be built into the SQL.
Dec 25 '12 #20
NeoPa
32,557 Recognized Expert Moderator MVP
MLEBL:
Neopa, thanks for your honesty. I appreciate the feedback, but I'll look to Z or Rabbit for direction.
I'm perfectly happy with this. An appropriate response in my book.
Rabbit:
Unless the requirements are significantly more complex than this scenario, there's no need for all that code. But most any other requirements you need can be built into the SQL.
This largely expresses my views on the matter. You won't get much better understanding or help on SQL matters than from Rabbit, but I would draw your attention to the idea of overlapping time periods, as discussed in the link from post #11. It is something that many people struggle to deal with properly, yet the fundamental logic of it is not too long and complicated (It's just so counter-intuitive for most people) :
Definition of Terms :
Period 1 is from time A to time B.
Period 2 is from time X to time Y.
Criteria :
(X <= B) AND (Y >= A)

If both parts of this logic statement are determined to be TRUE then there is an overlap. If a touching overlap (where one starts immediately as the other ends) is not to be considered then lose the equals (=s).
Dec 25 '12 #21
MLEBL
25 New Member
Maybe I need more direction on this, but I think this would require a rebuild of my table for my staffing model as well as the count table (and several forms, reports, and queries). The staffing model table is built in the same format as the count table for ease of comparison. Would this be correct?
Dec 26 '12 #22
MLEBL
25 New Member
I actually found my own solution. I replaced the docmd.requery line with docmd.refreshrecord and it stopped erroring and functions properly. Thanks for everyone's assistance.
Dec 26 '12 #23
Rabbit
12,516 Recognized Expert Moderator MVP
I'm glad you got it working but I want to caution you against the approach you've taken. It would behoove you to take a little extra time to do things correctly right now rather than taking a lot of extra time later on when changes come down the line.

As far as post #22, the SQL solution does not require changing the design of the staffing table.
Dec 27 '12 #24
NeoPa
32,557 Recognized Expert Moderator MVP
I'm with Rabbit on this. I haven't determined for myself that no changes would be required (or even the reverse), but whatever changes are required to do it properly, were much better done now than later on when the pain will certainly be greater. That is the nature of such things. Experience teaches us this time and again.
Dec 27 '12 #25

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

Similar topics

3
3939
by: Mohammed Mazid | last post by:
Hi, Basically I have a problem with registering to my quiz system. I had borrowed some code from an existing program but I just do not know why it doesn't work. If (txtUsername = "" Or...
5
2943
by: Darrel | last post by:
I have a web form that inserts a record into a DB. This function is called from the button_click subroutine. After the record is inserted, I show/hide some different panels and let the page...
1
1992
by: pcnorb | last post by:
I have a form, pulling data from a Products table that has many fields that do lookups to other tables. These are in a one-to-many relationship to a pk in each of said tables. I'd like to be...
3
1843
by: larry | last post by:
Ok I am re-coding our apps in PHP and am looking for ways to make parts easily updateable, One of the challenges in my field (non-rpofit) are various lookup tables (for incomes etc). An example...
0
1213
by: pravin gawande | last post by:
Hi Folks, I wanted to put check for the existing table. I got the table entry in two different tables. 1. SYSCAT.TABLES 2. SYSIBM.TABLES
6
4530
by: teser3 | last post by:
I have my PHP inserting into Oracle 9i. But how do I prevent duplicate record entries? I only have 3 fields in the insert in the action page: CODE <?php $c=OCILogon("scott", "tiger",...
8
2145
by: adigga1 | last post by:
I am building a Patient Medical Billing Database and I will be entering duplicate information from time to time, such as, entering a patient that has received a Chest X-ray twice or three time on...
1
14800
by: harsh85 | last post by:
"Cannot add duplicate collection entry" this error is coming when i go for browsing my website for which i have created virtual directory on my vista pc what are the settings to perfectly activevate...
4
1848
by: Talnus | last post by:
This question is completely backwards, to what a database is suppose to do, however because of the interaction between two systems it needs to be this way. I am looking for some way to have a report...
8
1746
by: MOCaseA | last post by:
Hello again, I am having problems in designing a (hopefully) simple, I think it would be a query. Here is the issue: I have a table that tracks time spent on specific tasks. It only hase a few...
0
7228
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
7128
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
7332
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
7058
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
7502
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
4715
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...
0
3206
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...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
426
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.