Private Sub PostReasonCodes_Click()
Dim strSQL As String
Dim str2SQL As String
Dim rst As Recordset
Dim MO As String
Dim WO As Long
Dim ReasonCodeVar As String
If Me.Dirty Then Me.Dirty = False
answer = MsgBox("Are you sure you would like to post the new reason codes dates to the system?", 4, "Verify")
If answer = vbYes Then
On Error GoTo Err_PostReasonCodes_Click
'SQL statement to get WO/MO, Reason Code and group, sorted by the WO then MO
strSQL = "SELECT STRUDEX_PRP010.[PRCTL#], [STRUDEX_PRP010]![PRCMPY] & [STRUDEX_PRP010]![PRORD#] AS MO " & _
"FROM (WO_Schedule INNER JOIN STRUDEX_PRP010 ON WO_Schedule.[WO#] = STRUDEX_PRP010.[PRCTL#]) INNER JOIN STRUDEX_OPL010B ON " & _
"(STRUDEX_PRP010.PROLNE = STRUDEX_OPL010B.O1LINE) AND (STRUDEX_PRP010.[PRORD#] = STRUDEX_OPL010B.[O1ORD#]) AND (STRUDEX_PRP010.PRCMPY = STRUDEX_OPL010B.O1CMPY) " & _
"GROUP BY STRUDEX_PRP010.[PRCTL#], [STRUDEX_PRP010]![PRCMPY] & [STRUDEX_PRP010]![PRORD#] ORDER BY STRUDEX_PRP010.[PRCTL#], [STRUDEX_PRP010]![PRCMPY] & [STRUDEX_PRP010]![PRORD#]"
'Opens the data read only as we dont need to change it
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
If rst.RecordCount > 0 Then
rst.MoveFirst
WO = rst![PRCTL#]
MO = rst![MO]
Forms!WOs_MOs!ReasonCode.SetFocus
ReasonCodeVar = IIf(IsNull(ReasonCode.Text), "N/A", ReasonCode.Text)
'Checks to see if the Reason Code has been selected
If ReasonCodeVar = "N/A" Then
MsgBox (WO + "" + "does not have a reason code assigned to it, processing aborted")
On Error GoTo Err_Reason_Code_Not_Assigned
End IfEnd If
'Terminates the run of the program
Exit_PostReasonCodes_Click:
Exit Sub
'Error occurs if Reason code field is blank when user posts reason code
Err_Reason_Code_Not_Assigned:
MsgBox ("Data Error 01")
Resume Exit_PostReasonCodes_Click
'General Error
Err_PostReasonCodes_Click:
MsgBox Err.Description
Resume Exit_PostReasonCodes_Click
End If
End Sub