VBA MS 访问函数
以下函数用于评估过程 CheckEventDataIntegrity 调用的日期。这仅适用于事件,但现在我想添加零件编号以及事件类型。意味着它应该评估带有事件和零件编号的日期。我该怎么做?
'-----------------------------
'-----------------------------
' 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
由 CheckEventDataIntegrity 过程调用,如下所示:
'-------------------------------- '----------------------------- ' 过程:检查事件数据完整性 ' 目的:验证是否遵循流程逻辑,这检查排序 '----------------------------- 函数 CheckEventDataIntegrity(fl1 As Boolean) 出错时转到 CheckEventDataIntegrity_Error
Do While fl1 = True
'事件类型 #1a 如果 Me!EventTypeSelected = "1a 分配 - 至检查器队列" 那么 If EvaluateDates("1 Receive NEW from Detailer") = False Then ' 包装尚未分配给 Checker 检查事件数据完整性 = False 退出功能 别的 ' 检查事件数据完整性 = True 退出执行 结束如果 结束如果 '事件类型#2 如果 Me!EventTypeSelected = "2 ReV - 作业" 那么 If EvaluateDates("1 Receive NEW from Detailer") = False Then ' 包装器尚未分配给审阅者 检查事件数据完整性 = False 退出功能 别的 退出执行 结束如果 结束如果
----
------
-----
fl1 = False 环形 '没有任何测试失败 CheckEventDataIntegrity = True
错误时转到 0 退出功能 检查事件数据完整性错误: MsgBox“错误”&错误编号和错误号VBA 文档 Form_frmEventLog_Input 的过程 CheckEventDataIntegrity 中的 (" & Err.Description & ")" 结束函数
我可以在评估函数中添加零件号,如下所示:
Private Function EvaluateDates(et As String, pn As String)
varx = DLookup("[EventDate]", "tblEventLog", "[TrackingNumber] = '" & Me!TrackingNumber & "' And [EventTypeSelected] = '" & et & "' And [PartNumber] = '" & Pn & "'")
但是如何在 CheckEventDataIntegrity 过程中实现它?
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 implement it in the CheckEventDataIntegrity procedure??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在学习 VBA,正在从事我的第一个项目。
我对此得到了答案。
I am learning VBA, working on my first project.
I got an answer for this.