0

我正在尝试为一串日期的每个实例创建一个文档。

然而,这并没有像我希望的那样工作——该字段没有更新,调试器根本没有向我显示任何东西。

有人可以用我的代码为我指明正确的方向吗?

Public Sub co_multiDates()

'Basic Error Handler function
'On Error GoTo errorHandler
'errorHandler:  MsgBox("ERROR " & CStr(Err) & ": " & Error$ & " on line " & CStr(Erl))

'Everything below this is designed to populate a field that then populates a column with multiple date values
'This is designed so that when creating a location record for multiple days, there will be multiple entries in the employee's view
Dim w As New NotesUIWorkspace       
Dim multiStartDate As NotesDateTime
Dim multiEndDate As NotesDateTime
Dim tempDate As NotesDateTime
Dim dateArray() As NotesDateTime
Dim dateCounter As Integer
Dim AdjustDay As Integer
Dim Source As NotesUIDocument
Set Source = w.CurrentDocument
Dim thisDoc As NotesDocument
Set thisDoc = Source.Document

' populate multiStartDate and multiEndDate with the values from the StartDate and EndDate fields
Set multiStartDate = New NotesDateTime(thisDoc.GetItemValue("StartDate")(0))
Set multiEndDate = New NotesDateTime(thisDoc.GetItemValue("EndDate")(0))

'assign null value to dateCounter   - calculates the difference between StartDate and EndDate
Let dateCounter = 0

While multiStartDate.TimeDifference(multiEndDate) <= 0

    'add to MultiDates
    ReDim Preserve dateArray(0 To dateCounter)
    Set tempDate = New NotesDateTime(multiStartDate.DateOnly)
    Set dateArray(dateCounter) = tempDate

    'add 1 to the date to loop
    Call multiStartDate.AdjustDay(1)
    dateCounter = dateCounter + 1
Wend

'Replaces the value of the MultiDatesArray field in newDoc (current document)  with the value of dateArray
Call thisDoc.ReplaceItemValue("MultiDates", dateArray)

'Updates audit trail field with any changes
Call SetAuditTrail(w.CurrentDocument.document, "auditTrailField", 1,  "PersonName", "Person Name")

End Sub

我觉得我可能遗漏了一些非常明显的东西。

谢谢。

4

2 回答 2

1

基于您正在使用 UI 类并更新文档这一事实,我假设您在 Notes 客户端中从在编辑模式下打开的文档中运行此代码,因此我通过添加上述内容在该上下文中对其进行了测试包含字段 StartDate、EndDate 和 Multidates 的表单的子代码,并从该表单上按钮的 Click 事件中调用它。它将 StartDate 和 EndDate 之间的每个日期添加到字段 Multidates,这似乎正是它的预期目的。

如果要为范围内的每个日期创建一个文档,则需要在 While 循环中添加代码来执行此操作,例如:

' In your declarations...
Dim session as NotesSession
Dim thisDatabase as NotesDatabase
Set thisDatabase=session.CurrentDatabase

' In your loop...
Set newDoc=thisDatabase.CreateDocument
newDoc.Form="ChildForm" ' or whatever 
newDoc.myDate=dateArray(dateCounter)
' Do other stuff to the document, then...
Call newDoc.Save(False, True)

如果我的上述任何假设不成立,请使用有关上下文的更多详细信息来编辑您的问题,您将得到更好的答案。

于 2012-01-24T17:11:59.317 回答
0

我不确定这个函数应该做什么:Call SetAuditTrail(w.CurrentDocument.document, "auditTrailField", 1, "PersonName", "Person Name")

但是在其余代码中,我看不到任何保存当前和/或新文档的创建。thisDoc.save(false,true)可能有帮助。

我看不出调试器不运行此代码的原因。

于 2012-01-24T14:28:45.960 回答