I am working on a schedule program and am having trouble getting the program to schedule all employees at once. I created a form based on a schedule set table which has the fields: ID, PostID, PositionID, TourID, EmpID. I also have a subfrom based on the legs table- fields: TourID, Sequence, On, Off. The subform is linked to the main form by TourID. I have 5 unbound fields Startdate, Enddate, datestep, Countit1 (record count of main form) and Countit (record count of subform). When the ScheduleAll button is clicked it adds 13 days to the startdate field for the enddate value, and copies startdate for datestep value. The program should then loop through each record and loop through the subform records to call an append query which adds the Date, EmpID, PostID, PosID, ScheduleID to a table. The program loops through the first record and subform sequence just fine. On the second record to the last record of the main form the looping does not occur for the subform. Not sure why the looping does not occur. I have tried Do While, Do Until, For Next all with the same results. I have also tried all possible combinations of removing/adding the .refresh command I am also having trouble with the date field. The append query is using the unbound control datestep on the main form but appends either nothing or square boxes. Here is the code.
Private Sub SchdAll_Click()
On Error GoTo Err_SchdAll_Click
Dim stDocName As String
Dim x, y, s, t, subtrec, trec As Integer
Dim datex As Date
trec = [countit1]
t = 0
Do Until t >= trec
datex = Startd
datestep = datex
subtrec = [countit]
s = 0
[tbl legs subform1].SetFocus
Do Until s >= subtrec
x = 0
y = 0
Do While x < Forms![frm scheduleit]![tbl legs subform1]![On]
stDocName = "qry TourtempAll ONtest2"
DoCmd.OpenQuery stDocName, acNormal, acEdit
datex = datex + 1
datestep = datestep + 1
Me.Refresh
x = x + 1
Loop
Do While y < Forms![frm scheduleit]![tbl legs subform1]![Off]
datex = datex + 1
datestep = datestep + 1
Me.Refresh
y = y + 1
Loop
stDocName = "qry Update Off Dates2"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.GoToRecord , , acNext
s = s + 1
Loop
schdID.SetFocus
DoCmd.GoToRecord , , acNext
t = t + 1
Me.Refresh
Loop
Exit_SchdAll_Click:
Exit Sub
Err_SchdAll_Click:
MsgBox Err.Description
Resume Exit_SchdAll_Click
End Sub
Private Sub SchdAll_Click()
On Error GoTo Err_SchdAll_Click
Dim stDocName As String
Dim x, y, s, t, subtrec, trec As Integer
Dim datex As Date
trec = [countit1]
t = 0
Do Until t >= trec
datex = Startd
datestep = datex
subtrec = [countit]
s = 0
[tbl legs subform1].SetFocus
Do Until s >= subtrec
x = 0
y = 0
Do While x < Forms![frm scheduleit]![tbl legs subform1]![On]
stDocName = "qry TourtempAll ONtest2"
DoCmd.OpenQuery stDocName, acNormal, acEdit
datex = datex + 1
datestep = datestep + 1
Me.Refresh
x = x + 1
Loop
Do While y < Forms![frm scheduleit]![tbl legs subform1]![Off]
datex = datex + 1
datestep = datestep + 1
Me.Refresh
y = y + 1
Loop
stDocName = "qry Update Off Dates2"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.GoToRecord , , acNext
s = s + 1
Loop
schdID.SetFocus
DoCmd.GoToRecord , , acNext
t = t + 1
Me.Refresh
Loop
Exit_SchdAll_Click:
Exit Sub
Err_SchdAll_Click:
MsgBox Err.Description
Resume Exit_SchdAll_Click
End Sub