Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    boywonder381's Avatar
    boywonder381 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Location
    Memphis, TN
    Posts
    28

    Unhappy The Error 3022 Duplicate Problem

    I'm having an issue with the Error 3022 per duplicate records. I know for a fact that I don't have duplicate records and for some reason it is telling me I do. I've changed the primary key to autonumber, all the rest of the fields to Yes (Duplicate is OK) to building a relationship between the tables. Nothing seems to work. Here is a sample of my code:

    Dim dbs As DAO.Database
    Dim rsClassRoom As DAO.Recordset
    Dim rsTempPhase As DAO.Recordset
    Dim rsHeadcountbyCourses As DAO.Recordset
    Dim rsTemp_Headcount1 As DAO.Recordset
    Dim rsScheduleCourses As DAO.Recordset
    Dim rsCourses As DAO.Recordset

    strClassroom = "SELECT * FROM [tblTraining_Rooms] ORDER BY tblTraining_Rooms.TimeEnd"
    Set rsClassRoom = dbs.OpenRecordset(strClassroom)
    rsClassRoom.MoveFirst

    ' Start adding records in tblSchedule_Courses table
    strSQL1 = "SELECT * FROM [tblSchedule_Courses]"
    Set rsScheduleCourses = dbs.OpenRecordset(strSQL1)

    'Adding code to tblSchedule_Course
    strSQL3 = "SELECT * FROM [Temp_Course_Headcount] ORDER BY CourseID"
    Set rsTemp_Headcount1 = dbs.OpenRecordset(strSQL3)

    Course = rsTemp_Headcount1!CourseTitle
    strCourses = "SELECT * FROM [tblCourses] WHERE [CourseTitle] = '" & Course & "'"
    Set rsCourses = dbs.OpenRecordset(strCourses)

    rsScheduleCourses.AddNew
    rsScheduleCourses![Courses] = "Overview"


    rsScheduleCourses![Duration] = rsCourses![TotalClassroomDuration]
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", rsCourses![TotalClassroomDuration], rsScheduleCourses![StartTime])
    TimeBeg = rsScheduleCourses![EndTime]
    rsScheduleCourses![EmpCount] = rsTemp_Headcount1![HeadcountTotalByCourse]
    rsScheduleCourses![Classroom] = "Cafeteria"
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update


    I might have missed adding something in this area, but for some reason, the code above is used in 2 locations of the OK button click procedure. It would give error 3022 and no reason I can think of.

    I really need to fix this to enjoy my holiday. Pls Helpppppppp!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I am going to guess that the code you posted here is not all of the code in your procedure.

    You are creating multiple recordsets yet, you do not use all of them. You add two records to one of the many DAO Recordsets that are instantiated. Nothing subsequent to your AddNew method indicates the creation of a duplicate record since you stated that all indexes are "allow duplicates". In other words, using addnew and populating fields that allow duplicates will not produce that error (if you are not adding info to a field indexed and no duplicates).

    EDIT: the only thing I can imagine is that your PK field is NOT an AutoNumber type. In this case you would need to add a value to the PK field manually.

  3. #3
    boywonder381's Avatar
    boywonder381 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Location
    Memphis, TN
    Posts
    28

    Error 3022 Duplicate is not Correct

    I did not place all of my code just the AddNew Methods that is giving me most of the problems. Do you need to see all of it?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What do you mean the code is used in 2 locations of the click procedure? Why would the code be in 2 locations of the same procedure? I would think that is an issue.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    boywonder381's Avatar
    boywonder381 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Location
    Memphis, TN
    Posts
    28
    I'm creating a scheduler in which the AddNew method add records based on different scenarios and I use a prep time after each course, which are added in two areas of the code.

  6. #6
    boywonder381's Avatar
    boywonder381 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Location
    Memphis, TN
    Posts
    28
    Here is all of the code:

    Dim dbs As DAO.Database
    Dim rsPhaseRoles As DAO.Recordset
    Dim rsRoleCourses As DAO.Recordset
    Dim rsShifts As DAO.Recordset
    Dim rsEvents As DAO.Recordset
    Dim rsClassRoom As DAO.Recordset
    Dim rsTempPhase As DAO.Recordset
    Dim rsHeadcountbyCourses As DAO.Recordset
    Dim rsTemp_Headcount1 As DAO.Recordset
    Dim rsScheduleCourses As DAO.Recordset
    Dim rsCourses As DAO.Recordset
    Dim N As Integer
    Dim R As Integer
    Dim j, C As Integer
    Dim inTemp1 As Integer
    Dim inTemp2 As Integer
    Dim inScheduler As Integer
    Dim strSQL, strSQL1, strSQL2, strSQL3, strShifts, strRoles As String
    Dim strDivide As String
    Dim strAsk As String
    Dim strPhase As String
    Dim MinAmt As Date
    Dim HCountCalc As Integer
    Dim Phasebx As String
    Dim NikeRecordCount As Integer
    Dim L As Integer
    Dim TrngRoom As String
    Dim DateFrom, DateTo As Date
    Dim RoleCount, RoleCount2 As Double
    Dim RoleDesc As String
    Dim EmpCount As Double
    Dim Course As String
    Dim strCourses As String
    Dim strClassroom As String
    Dim Ranking As Integer
    Dim TimeBeg As Date
    Dim LunchBeg As Date
    Dim LunchEnd As Date
    Dim DN As Integer
    Dim TimeEnd As Date
    Dim Msg, Style, Response, Title As String
    Msg = "You entered the wrong user ID or password. Try again."
    Style = vbOK
    Title = "Password Error"
    If Forms!frmLogin!txtID = "admin" And Forms!frmLogin!txtPw = "password" = False Then
    Response = MsgBox(Msg, Style, Title)
    Exit Sub
    End If
    Set dbs = CurrentDb
    ' Start adding records in tblSchedule_Courses table
    strSQL1 = "SELECT * FROM [tblSchedule_Courses]"
    Set rsScheduleCourses = dbs.OpenRecordset(strSQL1)
    strShifts = "SELECT * FROM [tblShifts]"
    Set rsShifts = dbs.OpenRecordset(strShifts)
    rsShifts.MoveFirst
    Do Until rsShifts.EOF
    strShifts = rsShifts!Shift
    DateFrom = Forms![frmSchedulerDialog]![txtFrom]
    TimeBeg = rsShifts!TimeBeg
    TimeEnd = rsShifts!TimeEnd
    LunchBeg = rsShifts!LunchBeg
    LunchEnd = rsShifts!LunchEnd
    L = 0

    'Copy Headcount records and divide by shifts to Temp table
    strSQL = "SELECT * FROM [tblHeadcount_By_Course_Phase]ORDER BY [CourseID]"
    Set rsHeadcountbyCourses = dbs.OpenRecordset(strSQL)
    DoCmd.RunSQL "DELETE * FROM [Temp_Course_Headcount]"
    strSQL3 = "SELECT * FROM [Temp_Course_Headcount]"
    Set rsTemp_Headcount1 = dbs.OpenRecordset(strSQL3)
    rsHeadcountbyCourses.MoveFirst
    strDivide = Forms!frmSchedulerDialog!txtDivide
    Do Until rsHeadcountbyCourses.EOF
    rsTemp_Headcount1.AddNew
    rsTemp_Headcount1![CourseID] = rsHeadcountbyCourses!CourseID
    rsTemp_Headcount1![CourseTitle] = rsHeadcountbyCourses!CourseTitle
    rsTemp_Headcount1![HeadcountTotalByCourse] = rsHeadcountbyCourses!HeadcountTotalByCourse / strDivide
    rsTemp_Headcount1.Update
    rsHeadcountbyCourses.MoveNext
    Loop

    strClassroom = "SELECT * FROM [tblTraining_Rooms] ORDER BY tblTraining_Rooms.TimeEnd"
    Set rsClassRoom = dbs.OpenRecordset(strClassroom)
    rsClassRoom.MoveFirst

    Phasebx = Forms![frmSchedulerDialog]![cmbPhase]
    TrngRoom = rsClassRoom![TrainingRoomName]

    'Adding code to tblSchedule_Course
    strSQL3 = "SELECT * FROM [Temp_Course_Headcount] ORDER BY CourseID"
    Set rsTemp_Headcount1 = dbs.OpenRecordset(strSQL3)
    rsHeadcountbyCourses.Close
    Set rsHeadcountbyCourses = Nothing
    rsTemp_Headcount1.MoveFirst
    Do Until rsTemp_Headcount1.EOF
    Course = rsTemp_Headcount1!CourseTitle
    strCourses = "SELECT * FROM [tblCourses] WHERE [CourseTitle] = '" & Course & "'"
    Set rsCourses = dbs.OpenRecordset(strCourses)
    'If DateAdd("n", rsCourses![TotalClassroomDuration], TimeBeg) < LunchBeg Then
    'TimeBeg = rsShifts!LunchEnd
    'End If

    If rsCourses![CourseTitle] = "Overview Course" Then

    If rsClassRoom![TrainingRoomName] <= "Cafeteria" Then
    Do Until rsClassRoom.EOF
    If rsClassRoom![TrainingRoomName] <= "Cafeteria" Then
    rsClassRoom.MoveNext
    Else
    GoTo NextStepX
    End If
    Loop
    End If

    ElseIf rsClassRoom![TrainingRoomName] = "Cafeteria" Then
    rsClassRoom.MoveNext
    ElseIf rsCourses!PCRequired = True Then
    If rsClassRoom![NumberPlayerPCs] <= 0 Then
    If rsClassRoom.EOF Then
    rsClassRoom.MoveFirst
    Else
    rsClassRoom.MoveNext
    End If
    End If
    End If

    k = 0
    NextStepX:
    If rsTemp_Headcount1!CourseTitle = "Overview" Then
    rsScheduleCourses.AddNew
    rsScheduleCourses![Courses] = "Overview Course"
    rsScheduleCourses![Duration] = rsCourses![TotalClassroomDuration]
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", rsCourses![TotalClassroomDuration], rsScheduleCourses![StartTime])
    TimeBeg = rsScheduleCourses![EndTime]
    rsScheduleCourses![EmpCount] = rsTemp_Headcount1![HeadcountTotalByCourse]
    rsScheduleCourses![Classroom] = "Cafeteria"
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update
    'Add Prep Time event along with right classroom time.
    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    TimeBeg = rsScheduleCourses![EndTime]
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsClassRoom.MoveFirst
    Do Until rsClassRoom.EOF
    rsClassRoom.Edit
    rsClassRoom!TimeEnd = TimeBeg
    rsClassRoom.Update
    rsClassRoom.MoveNext
    Loop

    rsClassRoom.MoveFirst
    rsClassRoom.MoveNext
    GoTo NextStepC
    End If

    ClassroomNextRecord:

    If TimeBeg = rsShifts!TimeBeg Then

    If strShifts = "D312" Then
    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15

    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Lunch Time"
    rsScheduleCourses![StartTime] = rsShifts!LunchBegin
    rsScheduleCourses![EndTime] = rsShifts!LunchEnd
    rsScheduleCourses![Duration] = 45
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = rsShifts!TimeEnd
    rsScheduleCourses![EndTime] = rsShifts!TimeEnd + 15
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update
    ElseIf strShifts = "D410" Then
    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![StartTime] = #5:45:00 AM#
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Lunch Time"
    rsScheduleCourses![StartTime] = rsShifts!LunchBegin
    rsScheduleCourses![EndTime] = rsShifts!LunchEnd
    rsScheduleCourses![Duration] = 45
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = rsShifts!TimeEnd
    rsScheduleCourses![EndTime] = rsShifts!TimeEnd + 15
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update
    ElseIf strShifts = "D5x8" Then
    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![StartTime] = #7:45:00 AM#
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Lunch Time"
    rsScheduleCourses![StartTime] = rsShifts!LunchBegin
    rsScheduleCourses![EndTime] = rsShifts!LunchEnd
    rsScheduleCourses![Duration] = 45
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = rsShifts!TimeEnd
    rsScheduleCourses![EndTime] = rsShifts!TimeEnd + 15
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update
    ElseIf strShifts = "E312" Then
    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![StartTime] = #5:45:00 PM#
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Lunch Time"
    rsScheduleCourses![StartTime] = rsShifts!LunchBegin
    rsScheduleCourses![EndTime] = rsShifts!LunchEnd
    rsScheduleCourses![Duration] = 45
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = rsShifts!TimeEnd
    rsScheduleCourses![EndTime] = rsShifts!TimeEnd + 15
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update
    ElseIf strShifts = "E410" Then
    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![StartTime] = #5:45:00 PM#
    rsScheduleCourses![EndTime] = TimeEnd
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Lunch Time"
    rsScheduleCourses![StartTime] = rsShifts!LunchBegin
    rsScheduleCourses![EndTime] = rsShifts!LunchEnd
    rsScheduleCourses![Duration] = 45
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = rsShifts!TimeEnd
    rsScheduleCourses![EndTime] = rsShifts!TimeEnd + 15
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update
    End If
    End If
    'If TimeBeg >= rsShifts!LunchBegin Then
    ' If L = 0 Then
    ' rsScheduleCourses![Courses] = "Lunch Time"
    ' rsScheduleCourses![StartTime] = rsShifts!LunchBegin
    ' rsScheduleCourses![EndTime] = rsShifts!LunchEnd
    ' L = 1
    'End If
    'End If

    HCountCalc = rsTemp_Headcount1!HeadcountTotalByCourse / rsClassRoom!Capacity
    If HCountCalc >= 2 Then

    If rsCourses!PCRequired = True Then
    If rsClassRoom![NumberPlayerPCs] <= 0 Then
    If rsClassRoom.EOF Then
    rsClassRoom.MoveFirst
    rsClassRoom.MoveNext
    Else
    rsClassRoom.MoveNext
    End If
    End If
    ElseIf rsClassRoom![TrainingRoomName] = "Cafeteria" Then
    If rsClassRoom.EOF Then
    rsClassRoom.MoveFirst
    rsClassRoom.MoveNext
    Else
    rsClassRoom.MoveNext
    End If
    End If
    j = 0
    C = 1
    For j = 1 To HCountCalc


    Phasebx = Forms![frmSchedulerDialog]![cmbPhase]
    TrngRoom = rsClassRoom![TrainingRoomName]


    rsScheduleCourses.AddNew
    rsScheduleCourses![Courses] = rsCourses![CourseTitle] & " " & C
    rsScheduleCourses![Duration] = rsCourses![TotalClassroomDuration]
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![StartTime] = rsClassRoom!TimeEnd
    rsScheduleCourses![EndTime] = DateAdd("n", rsScheduleCourses![Duration], rsScheduleCourses![StartTime])
    rsScheduleCourses![EmpCount] = rsTemp_Headcount1![HeadcountTotalByCourse] / HCountCalc
    rsScheduleCourses![Classroom] = TrngRoom
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Phasebx
    rsScheduleCourses.Update

    C = C + 1

    Next j
    'Add Prep Time event along with right classroom time.
    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", rsScheduleCourses![Duration], rsScheduleCourses!StartTime)

    rsClassRoom.Edit
    rsClassRoom!TimeEnd = rsScheduleCourses![EndTime]
    rsClassRoom.Update

    TimeBeg = rsScheduleCourses![EndTime]

    sScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Phasebx
    rsScheduleCourses.Update

    GoTo NextStepC
    End If

    'Placing classroom per Course Scheduler table
    TimeBeg = rsClassRoom!TimeEnd
    TrngRoom = rsClassRoom![TrainingRoomName]
    rsScheduleCourses.AddNew
    rsScheduleCourses![Courses] = rsTemp_Headcount1!CourseTitle
    rsScheduleCourses![Duration] = rsCourses!TotalClassroomDuration
    rsScheduleCourses![SchedDate] = DateFrom
    DN = Weekday(DateFrom)
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", rsCourses!TotalClassroomDuration, rsScheduleCourses!StartTime)
    TimeBeg = rsScheduleCourses![EndTime]
    rsClassRoom.Edit
    rsClassRoom!TimeEnd = rsScheduleCourses![EndTime]
    rsClassRoom.Update
    rsScheduleCourses!EmpCount = rsTemp_Headcount1!HeadcountTotalByCourse
    rsScheduleCourses![Classroom] = TrngRoom
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update
    strAsk = "* "
    If rsCourses!Fieldsimulation = True Then

    rsScheduleCourses.AddNew
    rsScheduleCourses![Courses] = strAsk + rsTemp_Headcount1!CourseTitle
    rsScheduleCourses![Duration] = rsCourses!TotalClassroomDuration
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", rsCourses!TotalClassroomDuration, rsScheduleCourses!StartTime)
    rsScheduleCourses![Classroom] = "Field Simulation"

    TimeBeg = rsScheduleCourses![EndTime]
    rsClassRoom.Edit
    rsClassRoom!TimeEnd = rsScheduleCourses![EndTime]
    rsClassRoom.Update

    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update
    End If

    'Adding Event PlaceHolder
    rsScheduleCourses.AddNew
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![SchedDate] = DateFrom

    If TimeBeg > rsShifts!TimeEnd Then

    If strShifts = "D312" Then
    If DN = 2 Then
    DateFrom = DateFrom + 5
    L = 0
    TimeBeg = rsShifts!TimeBeg
    Else
    DateFrom = DateFrom + 1
    L = 0
    TimeBeg = rsShifts!TimeBeg
    End If
    End If

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![StartTime] = #5:45:00 AM#
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Lunch Time"
    rsScheduleCourses![StartTime] = rsShifts!LunchBegin
    rsScheduleCourses![EndTime] = rsShifts!LunchEnd
    rsScheduleCourses![Duration] = 45
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = rsShifts!TimeEnd
    rsScheduleCourses![EndTime] = rsShifts!TimeEnd + 15
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    If strShifts = "D410" Then
    If DN = 6 Then
    DateFrom = DateFrom + 4
    L = 0
    TimeBeg = rsShifts!TimeBeg
    Else
    DateFrom = DateFrom + 1
    L = 0
    TimeBeg = rsShifts!TimeBeg
    End If

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![StartTime] = #7:45:00 AM#
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Lunch Time"
    rsScheduleCourses![StartTime] = rsShifts!LunchBegin
    rsScheduleCourses![EndTime] = rsShifts!LunchEnd
    rsScheduleCourses![Duration] = 45
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = rsShifts!TimeEnd
    rsScheduleCourses![EndTime] = rsShifts!TimeEnd + 15
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    End If
    If strShifts = "D5x8" Then
    If DN = 6 Then
    DateFrom = DateFrom + 3
    L = 0
    TimeBeg = rsShifts!TimeBeg
    Else
    DateFrom = DateFrom + 1
    L = 0
    TimeBeg = rsShifts!TimeBeg
    End If

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![StartTime] = #7:45:00 AM#
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Lunch Time"
    rsScheduleCourses![StartTime] = rsShifts!LunchBegin
    rsScheduleCourses![EndTime] = rsShifts!LunchEnd
    rsScheduleCourses![Duration] = 45
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = rsShifts!TimeEnd
    rsScheduleCourses![EndTime] = rsShifts!TimeEnd + 15
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    End If

    If strShifts = "E312" Then
    If DN = 3 Then
    DateFrom = DateFrom + 5
    L = 0
    TimeBeg = rsShifts!TimeBeg
    Else
    DateFrom = DateFrom + 1
    L = 0
    TimeBeg = rsShifts!TimeBeg
    End If
    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![StartTime] = #5:45:00 PM#
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Lunch Time"
    rsScheduleCourses![StartTime] = rsShifts!LunchBegin
    rsScheduleCourses![EndTime] = rsShifts!LunchEnd
    rsScheduleCourses![Duration] = 45
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = rsShifts!TimeEnd
    rsScheduleCourses![EndTime] = rsShifts!TimeEnd + 15
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    End If

    If strShifts = "E410" Then
    If DN = 7 Then
    DateFrom = DateFrom + 4
    L = 0
    TimeBeg = rsShifts!TimeBeg
    Else
    DateFrom = DateFrom + 1
    L = 0
    TimeBeg = rsShifts!TimeBeg
    End If

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Prep Time"
    rsScheduleCourses![StartTime] = #5:45:00 PM#
    rsScheduleCourses![EndTime] = TimeEnd
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Lunch Time"
    rsScheduleCourses![StartTime] = rsShifts!LunchBegin
    rsScheduleCourses![EndTime] = rsShifts!LunchEnd
    rsScheduleCourses![Duration] = 45
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsScheduleCourses.AddNew
    rsScheduleCourses![SchedDate] = DateFrom
    rsScheduleCourses![Courses] = "Team Huddle"
    rsScheduleCourses![StartTime] = rsShifts!TimeEnd
    rsScheduleCourses![EndTime] = rsShifts!TimeEnd + 15
    rsScheduleCourses![Duration] = 15
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    End If
    End If
    rsScheduleCourses![StartTime] = TimeBeg
    rsScheduleCourses![EndTime] = DateAdd("n", 15, rsScheduleCourses!StartTime)
    TimeBeg = rsScheduleCourses![EndTime]
    rsScheduleCourses![Shifts] = strShifts
    rsScheduleCourses![Phase] = Forms![frmSchedulerDialog]![cmbPhase]
    rsScheduleCourses.Update

    rsClassRoom.Edit
    rsClassRoom!TimeEnd = rsScheduleCourses![EndTime]
    rsClassRoom.Update
    If rsClassRoom.EOF Then
    rsClassRoom.MoveFirst
    Else
    rsClassRoom.MoveNext
    End If
    NextStepC:
    rsTemp_Headcount1.MoveNext
    Loop

  7. #7
    boywonder381's Avatar
    boywonder381 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Location
    Memphis, TN
    Posts
    28
    Here is an image of what it creates when I look at a report.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    That is a lot of code. It would be easier to read if you posted between code tags - the indentation would be preserved.

    Have you step debugged?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    boywonder381's Avatar
    boywonder381 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Location
    Memphis, TN
    Posts
    28
    Yes I debugged and seen where it get to the update part and then skip it and go to my error handling area and give me the 3022 error.

    If (Err.Number = 3022) Then
    Err.Clear
    Forms!frmLogin.Undo
    Resume Next
    Else
    Resume Next ' Pick up again and quit.
    End If

  10. #10
    boywonder381's Avatar
    boywonder381 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Location
    Memphis, TN
    Posts
    28
    Is this a MS Access problem or is this an error that is fixable?

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    There are a lot of Update lines in that code. Do they all error?

    The issue is certainly with your code. Finding out why is the challenge. I would need a better understanding of why you are using this process and probably have to debug the code myself. If you want to provide db for analysis, follow instructions at bottom of my post.

    What event is the code in?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    boywonder381's Avatar
    boywonder381 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Location
    Memphis, TN
    Posts
    28
    You can go to itclosure.com/images/AFormv16Sa.rar to download the app.

  13. #13
    boywonder381's Avatar
    boywonder381 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Location
    Memphis, TN
    Posts
    28
    Open the frmSchedulerDialog form
    Add a Date Range from 9/15/2014 to 9/30/2014
    Add 5 to the Divide by
    Select from the Phase 2D

    Click Create Scheduler

    Click OK to delete data from 2 tables

    Login using admin for the ID and password for the password

    Click OK to delete the same table 5 times and click No to create a History table.

    Open the Master Scheduler Report and you will see what I see.

  14. #14
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    boywonder381,

    As June7 said that's a lot of code.

    I'm going to suggest, as June did, that you encapsulate you code with code tags. You use a[c o d e ] at start of your vba and [ /c o d e ] at the end.
    Remove the spaces in the red text.

    You should also consider 2 free utilities that will help you with code structure, comments, error handling and readability.
    These are
    MZTools and SmartIndenter (I use smart indenter with Access 2010 )

    Also, regarding your code:

    This :
    Dim DateFrom, DateTo As Date
    Dim RoleCount, RoleCount2 As Double
    does not do what you think. Access vba requires you to explicitly Dim your variables.

    You must use
    Code:
    Dim  DateFrom as Date
    Dim  DateTo As Date
    or
    Code:
    Dim DateFrom as Date, DateTo As Date
    When you use Dim DateFrom, DateTo As Date
    DateFrom will be assigned Variant (the default) and DateTo will be Date datatype.

    Good luck.

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Sorry, I can't open rar files, only Windows Compression zip.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. duplicate error
    By msasan1367 in forum Access
    Replies: 3
    Last Post: 04-25-2013, 01:11 PM
  2. Replies: 4
    Last Post: 02-13-2013, 10:46 AM
  3. Replies: 4
    Last Post: 02-13-2012, 08:33 AM
  4. Problem with code to prevent duplicate entries
    By ResearchRN in forum Programming
    Replies: 5
    Last Post: 11-08-2011, 12:12 PM
  5. duplicate problem
    By hokie in forum Access
    Replies: 27
    Last Post: 07-13-2009, 01:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums