我以前写的一段代码。
用WebQueryOpen事件中的代理实现自动编号
Sub Initialize
 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim doc As NotesDocument
 Dim temp As NotesDocument
 Dim view As NotesView
 Dim item As NotesItem
 Dim months As String
 Dim flag As Long
 Dim formula As String
 Dim id As Integer
 Dim result As String
 Dim nows As NotesDateTime
 Set db=session.CurrentDataBase
 Set view=db.GetView("编号")
 Set doc=view.getfirstdocument
 months=Month(Now())
 If Len(months)<2 Then
  months="0"+months
 End If
 Set temp=session.DocumentContext 
 
 If  doc Is Nothing Then
  Msgbox "空"
  temp.自动编号=Year(Now())+months+"0001" 
  Goto save 
 End If
 
 Msgbox Mid(doc.自动编号(0),5,2)
 If Val(Mid(doc.自动编号(0),5,2))<>Month(Now()) Then
  temp.自动编号=Year(Now())+months+"0001" 
  Goto save 
 End If
 Msgbox Mid(doc.自动编号(0),1,4)
 If Val(Mid(doc.自动编号(0),1,4))<>Year(Now()) Then
  temp.自动编号=Year(Now())+months+"0001" 
  Goto save 
 End If
 
 result=doc.自动编号(0)+1
 
 temp.自动编号=result
save:
 Msgbox "结束"
 Call temp.Save(True,True)
End Sub