M
Mike Johnson
I providing the entire sub in case it's needed.
I've identified the problem within the code as remarks. Thanks
Public Sub Process_Monthly()
On Error GoTo Err_Ok_Bttn_Click
Dim dbsCurrent As DAO.Database
Dim rstRecords As DAO.Recordset
Dim dbsCurrent1 As DAO.Database
Dim rstRecords1 As DAO.Recordset
Dim dbsCurrent2 As DAO.Database
Dim rstRecords2 As DAO.Recordset
'Step 1. Add Qty_pd_to_dt to Qty_Instl_to_dt in Master_table
Set dbsCurrent = CurrentDb()
Set rstRecords = dbsCurrent.OpenRecordset("Master_Items_T")
If rstRecords.RecordCount <> 0 Then
rstRecords.MoveFirst
rstRecords.Bookmark = rstRecords.LastModified
End If
Do While Not rstRecords.EOF
rstRecords.Edit
rstRecords!QTY_INSTL_TO_DT = rstRecords!QTY_PD_TO_DT +
rstRecords!QTY_INSTL_TO_DT
rstRecords.Update
rstRecords.MoveNext
Loop
rstRecords.Close
dbsCurrent.Close
'Step 2. Add all Work Order Qty_pd_to_dt to Master_table
'Will need to check for match before updating item
Set dbsCurrent = CurrentDb()
Set rstRecords = dbsCurrent.OpenRecordset("WrkOdr_Names_T")
Set dbsCurrent2 = CurrentDb()
Set rstRecords2 = dbsCurrent.OpenRecordset("Master_Items_T")
If rstRecords.RecordCount <> 0 Then
rstRecords.MoveFirst
rstRecords.Bookmark = rstRecords.LastModified
End If
If rstRecords2.RecordCount <> 0 Then
rstRecords2.MoveFirst
rstRecords.Bookmark = rstRecords2.LastModified
End If
Do While Not rstRecords.EOF
'step through work orders
Set dbsCurrent1 = CurrentDb()
Set rstRecords1 =
dbsCurrent1.OpenRecordset(rstRecords!Work_Order_Name)
If rstRecords1.RecordCount <> 0 Then
rstRecords1.MoveFirst
rstRecords1.Bookmark = rstRecords1.LastModified
End If
Do While Not rstRecords.EOF
'
'Problem:
'When Work_Order_Name changes the rstRecords1
'needs to be updated to reflect the new record source
'not sure how to do this.
'
'I've tried adding the following code after the do while below.
'Set rstRecords1 =
dbsCurrent1.OpenRecordset(rstRecords!Work_Order_Name)
'If rstRecords1.RecordCount <> 0 Then
'rstRecords1.MoveFirst
'rstRecords1.Bookmark = rstRecords1.LastModified
'End If
'This seems to resolve the issue but for some reason will not
'move to the first record. When called. Label move first below
'
'Add to Qty Installed to Date to Qty Paid to Date
Do While Not rstRecords1.EOF
If rstRecords1!ITM_CD = rstRecords2!ITM_CD Then
rstRecords2.Edit
rstRecords2!QTY_INSTL_TO_DT =
rstRecords1!QTY_INSTL_TO_DT + rstRecords1!QTY_PD_TO_DT
rstRecords2.Update
rstRecords1.MoveNext
Else
rstRecords2.MoveNext
End If
Loop
rstRecords.MoveNext
rstRecords1.MoveLast 'Move first
rstRecords2.MoveFirst
Loop
Loop
rstRecords.Close
dbsCurrent.Close
rstRecords1.Close
dbsCurrent1.Close
'rstRecords2.Close
'dbsCurrent2.Close
Exit_Ok_Bttn_Click:
Exit Sub
Err_Ok_Bttn_Click:
MsgBox Err.Description
Resume Exit_Ok_Bttn_Click
End Sub
I've identified the problem within the code as remarks. Thanks
Public Sub Process_Monthly()
On Error GoTo Err_Ok_Bttn_Click
Dim dbsCurrent As DAO.Database
Dim rstRecords As DAO.Recordset
Dim dbsCurrent1 As DAO.Database
Dim rstRecords1 As DAO.Recordset
Dim dbsCurrent2 As DAO.Database
Dim rstRecords2 As DAO.Recordset
'Step 1. Add Qty_pd_to_dt to Qty_Instl_to_dt in Master_table
Set dbsCurrent = CurrentDb()
Set rstRecords = dbsCurrent.OpenRecordset("Master_Items_T")
If rstRecords.RecordCount <> 0 Then
rstRecords.MoveFirst
rstRecords.Bookmark = rstRecords.LastModified
End If
Do While Not rstRecords.EOF
rstRecords.Edit
rstRecords!QTY_INSTL_TO_DT = rstRecords!QTY_PD_TO_DT +
rstRecords!QTY_INSTL_TO_DT
rstRecords.Update
rstRecords.MoveNext
Loop
rstRecords.Close
dbsCurrent.Close
'Step 2. Add all Work Order Qty_pd_to_dt to Master_table
'Will need to check for match before updating item
Set dbsCurrent = CurrentDb()
Set rstRecords = dbsCurrent.OpenRecordset("WrkOdr_Names_T")
Set dbsCurrent2 = CurrentDb()
Set rstRecords2 = dbsCurrent.OpenRecordset("Master_Items_T")
If rstRecords.RecordCount <> 0 Then
rstRecords.MoveFirst
rstRecords.Bookmark = rstRecords.LastModified
End If
If rstRecords2.RecordCount <> 0 Then
rstRecords2.MoveFirst
rstRecords.Bookmark = rstRecords2.LastModified
End If
Do While Not rstRecords.EOF
'step through work orders
Set dbsCurrent1 = CurrentDb()
Set rstRecords1 =
dbsCurrent1.OpenRecordset(rstRecords!Work_Order_Name)
If rstRecords1.RecordCount <> 0 Then
rstRecords1.MoveFirst
rstRecords1.Bookmark = rstRecords1.LastModified
End If
Do While Not rstRecords.EOF
'
'Problem:
'When Work_Order_Name changes the rstRecords1
'needs to be updated to reflect the new record source
'not sure how to do this.
'
'I've tried adding the following code after the do while below.
'Set rstRecords1 =
dbsCurrent1.OpenRecordset(rstRecords!Work_Order_Name)
'If rstRecords1.RecordCount <> 0 Then
'rstRecords1.MoveFirst
'rstRecords1.Bookmark = rstRecords1.LastModified
'End If
'This seems to resolve the issue but for some reason will not
'move to the first record. When called. Label move first below
'
'Add to Qty Installed to Date to Qty Paid to Date
Do While Not rstRecords1.EOF
If rstRecords1!ITM_CD = rstRecords2!ITM_CD Then
rstRecords2.Edit
rstRecords2!QTY_INSTL_TO_DT =
rstRecords1!QTY_INSTL_TO_DT + rstRecords1!QTY_PD_TO_DT
rstRecords2.Update
rstRecords1.MoveNext
Else
rstRecords2.MoveNext
End If
Loop
rstRecords.MoveNext
rstRecords1.MoveLast 'Move first
rstRecords2.MoveFirst
Loop
Loop
rstRecords.Close
dbsCurrent.Close
rstRecords1.Close
dbsCurrent1.Close
'rstRecords2.Close
'dbsCurrent2.Close
Exit_Ok_Bttn_Click:
Exit Sub
Err_Ok_Bttn_Click:
MsgBox Err.Description
Resume Exit_Ok_Bttn_Click
End Sub