Below is the code that I currently have in the BeforeUpdate Event of Soe_Code. This works well. I have added a new wrinkle for this code as follows. If my FutureEffective field is true I do not want to find previous forms that are still open. That works!
Now my Dilemma: If the FutureEffective is false I want to find previous forms that are still open (that works too) but I do not want to include previous forms where FutureEffective is true. Right now if FutureEffective is false the code finds the latest Form that is open and takes me to that form. That form could have the FutureEffective box checked as true and I want to avoid that. If FutureEffective is false I just want to find the lastest fom that is still open but only where FutureEffective is false. I hope someone can assist me with this.
Now my Dilemma: If the FutureEffective is false I want to find previous forms that are still open (that works too) but I do not want to include previous forms where FutureEffective is true. Right now if FutureEffective is false the code finds the latest Form that is open and takes me to that form. That form could have the FutureEffective box checked as true and I want to avoid that. If FutureEffective is false I just want to find the lastest fom that is still open but only where FutureEffective is false. I hope someone can assist me with this.
Code:
Private Sub ctrSoeCode_BeforeUpdate(Cancel As Integer)
Dim Rs As DAO.Recordset
Dim count As Integer, Criteria As String
Dim chgDate, Worker As String, Form As String
Dim SL As String, DL As String
Dim msg As String, Style As Integer, Title As String
Me.Process = Me.ctrSoeCode.Column(2)
Me.SOE_Description = Me.ctrSoeCode.Column(1)
SL = vbNewLine
DL = SL & SL
Criteria = "([Soe_Code] = '" & Me.ctrSoeCode.Column(0) & "') AND " & _
"([OMS Completed] = False)"
count = DCount("[Soe_Code]", "all_trucks_table", Criteria)
chgDate = DMax("[date_of_Change]", "all_trucks_table", Criteria)
If IsNull(chgDate) Then
'Msg = "Cannot aquire date!" & DL & _
' "No Records Returned matching Criteria!"
'Style = vbCritical + vbokobnly
'Title = "No Date Error! . . ."
'MsgBox Msg, Style, Title
Else
Criteria = "([Soe_Code] = '" & Me.ctrSoeCode.Column(0) & "') AND " & _
"([OMS Completed] = False) AND " & _
"[Date_of_Change] = #" & chgDate & "#"
Worker = DLookup("[Soe_Worker]", "all_trucks_table", Criteria)
Form = DLookup("[Form #]", "all_trucks_table", Criteria)
If Me.FutureEffective = False And count > 0 Then
msg = "SOECode: " & Me.ctrSoeCode.Column(0) & " is still open " & count & " Time(s)." & DL & _
"Latest Time: " & Format(chgDate, "General Date") & SL & _
"Latest User: " & Worker & DL & _
"Latest Form: " & Form & DL & _
"The OMS for this SOE is currently being worked on. " & DL & _
"1. Click OK (you will automatically go to the Form shown above) " & SL & _
"2. Add new changes (in the SOE Change Details Box)" & SL & _
"3. Make sure you put today's date with your new changes" & SL & _
"4. Un-check and Re-check the SOE Ready for OMS Check Box"
Style = vbInformation + vbOKOnly
Title = "Consolidation Notice!"
MsgBox msg, Style, Title
'then after the MsgBox line...
Set Rs = Me.RecordsetClone
Rs.FindFirst "[Form #] = " & Form
If Not Rs.EOF Then
Me.Undo
Cancel = True
Me.Bookmark = Rs.Bookmark
End If
Else
If Me.FutureEffective = True Then
Me.Process = Me.ctrSoeCode.Column(2)
Me.SOE_Description = Me.ctrSoeCode.Column(1)
End If
End If
End If
End Sub