VBA MS access functions
Following function is for evaluating dates called by procedure CheckEventDataIntegrity. This does only for events but now I want to add partnumber along with event type. Means it should evaluate dates with event and partnumber.How Can I do this??
'-----------------------------
'-----------------------------
' Function : EvaluateDates
' Purpose : flags date sequencing errors, called by CheckEventDataIntegrity
'-----------------------------
Private Function EvaluateDates(et As String)
Dim varx As Variant
On Error GoTo EvaluateDates_Error
varx = DLookup("[EventDate]", "tblEventLog", "[TrackingNumber] = '" & Me!TrackingNumber & "' And [EventTypeSelected] = '" & et & "'")
If IsNull(varx) Then ' predecessor event does not exist
displayMsgBox = _
MsgBox("No '" & et & "' event has been Recorded. Please correct.", _
vbCritical)
EvaluateDates = False
Exit Function
End If
If varx > Me!EventDate Then ' predecessor event exists but date is after date being posted
displayMsgBox = _
MsgBox("Chronological Error. Previously posted '" & et & "' event has date stamp that is later than date stamp of completion event you are now attempting to post. Please verify date of event you are now posting. If it is correct than contact admin.", _
vbCritical)
EvaluateDates = False
Exit Function
End If
EvaluateDates = True
On Error GoTo 0
Exit Function
EvaluateDates_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure EvaluateDates of VBA Document Form_frmEventLog_Input"
End Function
called by CheckEventDataIntegrity procedure as follows:
'----------------------------- '----------------------------- ' Procedure : CheckEventDataIntegrity ' Purpose : verifies process logic is being followed, this checks for sequencing '----------------------------- Function CheckEventDataIntegrity(fl1 As Boolean) On Error GoTo CheckEventDataIntegrity_Error
Do While fl1 = True
'event type #1a If Me!EventTypeSelected = "1a Assign - To Checker Queue" Then If EvaluateDates("1 Receive NEW from Detailer") = False Then ' wrapper has not been assigned to Checker CheckEventDataIntegrity = False Exit Function Else ' CheckEventDataIntegrity = True Exit Do End If End If 'event type #2 If Me!EventTypeSelected = "2 ReV - Assignment" Then If EvaluateDates("1 Receive NEW from Detailer") = False Then ' wrapper has not been assigned to reviewer CheckEventDataIntegrity = False Exit Function Else Exit Do End If End If
----
------
-----
fl1 = False Loop 'nothing failed test CheckEventDataIntegrity = True
On Error GoTo 0 Exit Function CheckEventDataIntegrity_Error: MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure CheckEventDataIntegrity of VBA Document Form_frmEventLog_Input" End Function
I can add partnumber as follows in the evaluatedates function:
Private Function EvaluateDates(et As String, pn As String)
varx = DLookup("[EventDate]", "tblEventLog", "[TrackingNumber] = '" & Me!TrackingNumber & "' And [EventTypeSelected] = '" & et & "' And [PartNumber] = '" & Pn & "'")
But how can I implemen开发者_运维技巧t it in the CheckEventDataIntegrity procedure??
I am learning VBA, working on my first project.
I got an answer for this.
精彩评论