Hi, all,
I need to allow the user to choose a field value from a list when creating a new doc in the view. The QUERY_REQUEST code works fine when editing an existing doc, but there’s no list for a new doc - just free-for-all manual entry.
Here is my code:
Sub Inviewedit(Source As Notesuiview, Requesttype As Integer, Colprogname As Variant, Columnvalue As Variant, Continue As Variant)
%REM
(copy/pasted directly from online Help)
In this view, the programmatic name of each editable column
is the same as the name of the field whose value it holds.
All the fields for the editable columns are simple Text.
Each editable column gets the same processing.
%END REM
REM Define constants for request types
Const QUERY_REQUEST = 1
Const VALIDATE_REQUEST = 2
Const SAVE_REQUEST = 3
Const NEWENTRY_REQUEST = 4
REM Define variables
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim caret As String
Dim ws As New NotesUIWorkspace
REM Get the CaretNoteID - exit if it does not point at a document
caret = Source.CaretNoteID
If caret = "0" Then Exit Sub
REM Get the current database and document
Set db = Source.View.Parent
Set doc = db.GetDocumentByID(caret)
REM Select the request type
Select Case Requesttype
Case QUERY_REQUEST
If Colprogname(0) = "TypeEmployee" Then
Redim Preserve emptype (8)
emptype (0) = "Applicant"
emptype (1) = "Employee"
emptype (2) = "Detail"
emptype (3) = "Contractor"
emptype (4) = "Intern"
emptype (5) = "Co-op"
emptype (6) = "Inactive"
emptype (7) = "Retired"
answer$ = ws.Prompt (PROMPT_OKCANCELLIST, "Type Employee", "Please select the correct type:", "", emptype)
If answer$ = EMPTY Then ' Cancel will return EMPTY, which will wipe out an existing value
Goto bypassreplace
End If
Call doc.ReplaceItemValue("TypeEmployee", answer$)
Call doc.Save(True, True, True) ' (Must save here, or the value w/b lost)
bypassreplace:
Continue = False ' (Keeps col. from being editable)
Call ws.ViewRefresh
Case VALIDATE_REQUEST
REM Cause validation error if user tries to exit column with no value
Select Case Colprogname(0)
' If district or division is blank, that's OK
Case "District"
Continue = True
Case "Division"
Continue = True
Case "DutyStn"
Continue = True
Case "FormsRecdDt"
Continue = True
Case "FormsRecdDt_1"
Continue = True
Case "FormsRecdDt_2"
Continue = True
Case "FormsRecdDt_3"
Continue = True
Case "FormsRecdDt_4"
Continue = True
Case Else
If Fulltrim(Columnvalue(0)) = "" Then
Messagebox "You must enter a value", 0 + 16 + 0 + 0, "No value in column"
Continue = False
End If
End Select
Case SAVE_REQUEST
REM Write the edited column view entries back to the document
For i = 0 To Ubound(Colprogname) Step 1
If Colprogname(i) = "DOB" Then
Dim dobdatevalue As Variant
dobdatevalue = Datevalue (Columnvalue(i))
Call doc.ReplaceItemValue(Colprogname(i), dobdatevalue)
Elseif Colprogname(i) = "StatusDt" Then
Dim statdatevalue As Variant
statdatevalue = Datevalue (Columnvalue(i))
Call doc.ReplaceItemValue(Colprogname(i), statdatevalue)
Elseif Colprogname(i) = "FormsRecdDt" Then
Dim formsdatevalue As Variant
formsdatevalue = Datevalue (Columnvalue(i))
Call doc.ReplaceItemValue(Colprogname(i), formsdatevalue)
Elseif Colprogname(i) = "$32" Then ' (contractor icon col.)
' This code only allows user to click on the icon to toggle it off or
' click on the blank space to toggle it on.
currentFieldValue = doc.GetItemValue ("Contractor_1")
If currentFieldValue(0) = "1" Then
Call doc.ReplaceItemValue ("Contractor_1", "")
Else
Call doc.ReplaceItemValue ("Contractor_1", "1")
End If
Else
Call doc.ReplaceItemValue(Colprogname(i), Columnvalue(i))
End If
Next
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
Case NEWENTRY_REQUEST
REM Create document and create “Form” item
REM Write column values to the new document
Set doc = New NotesDocument(db)
Call doc.ReplaceItemValue("Form", "Main")
For i = 0 To Ubound(Colprogname) Step 1
If Colprogname(i) = "DOB" Then
Dim newdobdatevalue As Variant
newdobdatevalue = Datevalue (Columnvalue(i))
Call doc.ReplaceItemValue(Colprogname(i), newdobdatevalue)
Elseif Colprogname(i) = "StatusDt" Then
Dim newstatdatevalue As Variant
newstatdatevalue = Datevalue (Columnvalue(i))
Call doc.ReplaceItemValue(Colprogname(i), newstatdatevalue)
Elseif Colprogname(i) = "FormsRecdDt" Then
Dim newformsdatevalue As Variant
newformsdatevalue = Datevalue (Columnvalue(i))
Call doc.ReplaceItemValue(Colprogname(i), newformsdatevalue)
Else
Call doc.ReplaceItemValue(Colprogname(i), Columnvalue(i))
End If
Next
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
End Select
End Sub
I understand that if caret = 0 then it exits the sub and thus never runs the QUERY_REQUEST code. But when you exit the first editable column, VALIDATE_REQUEST and NEWENTRY_REQUEST both run fine, and doc is set and saved, so shouldn’t caret then have a value? Then when you get to the column that should give the user a list, shouldn’t QUERY_REQUEST run?
(Obviously I’m not getting something since if that happened, NEWENTRY_REQUEST would set doc a second time.)
(A related question would be: how does it even get down to NEWENTRY_REQUEST to set and save the doc the first time, if caret causes the script to abort when it equals zero?)
TIA for any help getting the list box to appear for NEW docs!!
Mark