Date format when using InViewEdit

I am working on a view using InViewEdit on a column. The idée is to edit a date filed from the view. Using the script below I can edit the filed from the column. But, the problem appears when I change the value from the view. The value doesn’t displays as a date. I have to open and save the document before the value changes to Date. Please help………

Here is the scrip…

Sub Inviewedit(Source As Notesuiview, Requesttype As Integer, Colprogname As Variant, Columnvalue As Variant, Continue As Variant)

%REM

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

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

REM Reserved - do not use in Release 6.0

Case VALIDATE_REQUEST

REM Cause validation error if user tries to exit column with no value

	If Fulltrim(Columnvalue(0)) = "" Then

		Messagebox "You must enter a value",, "No value in column"

		Continue = False

	End If

	

Case SAVE_REQUEST

REM Write the edited column view entries back to the document

	For i = 0 To Ubound(Colprogname) Step 1

		Call doc.ReplaceItemValue(Colprogname(i), Columnvalue(i))

	Next

REM Save(force, createResponse, markRead)

	Call doc.ComputeWithForm( False, False)

	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", "fa_Saledescription")

	For i = 0 To Ubound(Colprogname) Step 1

		Call doc.ReplaceItemValue(Colprogname(i), Columnvalue(i))

	Next

REM Save(force, createResponse, markRead)

	Call doc.ComputeWithForm( False, False)

	Call doc.Save(True, True, True)

	

	

End Select

End Sub

Subject: Date format when using InViewEdit

The value entered into the column by the user is a text value. Even though the value may have been a date/time before the user started to edit it, they can type any characters into the cell, so a modified column value is given to you as text, even if it’s text that happens to look like a date. Your code in the Inviewedit event must convert the value to the desired datatype, in this case date/time. There are a couple of ways you could do this:Declare a New Notesdatetime object and give it the value entered into the column as an initializer.

After assigning fields, call ComputeWithForm method to adjust all fields to their correct datatypes.

The disadvantage to ComputeWithForm is that it may be slow. The big advantage to using it, is that your program is much simpler and the maintenance is easier (e.g. if you change the datatype of a field on the form). This applies not only to date/time fields, but to number fields, Author and Reader fields, multivalued fields of all sorts, etc.

Incidentally, the QUERY_REQUEST event is not “reserved”, you can certainly use it, and it’s very handy. For instance, you could put code in there so that when the user tries to edit a date column, instead of just letting them type anything they like, you could pop up a date picker dialog. Or for a keyword field, you can pop up a list of keyword choices instead of just letting the user enter any value.

Also, I suggest you don’t bother to fetch the current document before seeing what event you’re processing. It’s a waste of time to fetch the document every time the user enters or exits a cell, unless they are leaving the row and you need to save the document.

  • Andre Guirard
    IBM Lotus Software
    Enterprise Integration Team

Subject: RE: Date format when using InViewEdit

Hi all,How do we achieve the following -

When the user tries to edit a date column in InViewEdit, instead of just letting them type anything they like, can we pop up a date picker dialog and how??

An example code would be of great help.

Subject: Date format when using InViewEdit

I know this is a long time after the initial post but perhaps it will be helpful to someone just starting to look at InViewEdit.

Like Alon, I started with an example script from the Domino Designer Help database. I removed script for NEWENTRY_REQUEST because I didn’t want the ability to create a new doc at the view level, and the Help says not to use QUERY_REQUEST although I see in the other response to Alon’s query that it should be used to provide date pickers or pick lists. I have not seen any example code here or in Help (even 6.5) that explains how to use it.

To make the column editable, tick the property “Editable column” in the column properties.

Then add script to the InViewEdit event. This is the simple script I used. Hope it points someone in the right direction.

Sub Inviewedit(Source As Notesuiview, Requesttype As Integer, Colprogname As Variant, Columnvalue As Variant, Continue As Variant)

%REM

This view has one editable column, which is for a date. All edits in views are “text” so I

convert the text value to a date before saving.

%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 ws As New NotesUIWorkspace

Dim caret As String

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

REM Not using

Case VALIDATE_REQUEST

REM Cause validation error if user tries to exit column with no value

	If Fulltrim(Columnvalue(0)) = "" Then

		Messagebox "You must enter a value",, "No value in column"

		Continue = False

	End If

	

Case SAVE_REQUEST

REM Write the edited column view entry back to the document after converting the text to date format

	Dim aDateV As Variant

	aDateV = Datevalue(Columnvalue(0))		

	Call doc.ReplaceItemValue(Colprogname(0), aDateV)

	Call doc.Save(True, True, True)

	

Case NEWENTRY_REQUEST

REM Not allowing create at view level

	

End Select

End Sub