sexta-feira, 21 de janeiro de 2011

Verificar se o campo RichText esta vazio - How to check Rich Text field is empty or not

http://moorthidaniel.com/lotus-script/how-to-check-rich-text-field-is-empty-or-not/


here are several ways to validate a rich text field is empty or not. Here I have listed some of them.
Method 1.
The below method will work only for the rich text fields having only texts. If the field having attachments or links it wont work
Dim session As New NotesSession
Dim ws As NotesUIWorkspace
Set ws = New NotesUIWorkspace
 
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
 
Dim doc As NotesDocument
Dim item As NotesItem
 
Set doc = uidoc.Document
 
Set item = doc.GetFirstItem("Body")
Dim valStr As String
valStr$ = item.Abstract(80, True, False)
If (Fulltrim(valStr$) = "") Then
Msgbox "empty"
Else
Msgbox valStr$
End If
Mehtod 2
This method will work fine for attachments or links and even for imported images. Here we need the document should be in edit document
' Document should be in edit mode
On Error Goto ProcessError
Dim session As New NotesSession
Dim ws As NotesUIWorkspace
Set ws = New NotesUIWorkspace
 
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
 
currentfield = uidoc.CurrentField
If uidoc.EditMode = False Then
Msgbox "Document Should be in edit mode"
Exit Sub
End If
Call uidoc.GotoField("body")
Call uidoc.SelectAll
'This line will generate a 4407 error message if the Rich Text Field is null
Call uidoc.DeselectAll
Exit Sub
processError:
If Err = 4407 Then
Messagebox "RTF Field is empty"
Else
Msgbox Error & " - errno : " & Cstr(Err) & " @ line no - " & Cstr(Erl)
End If
Method 3
This method will fail only for imported images into rich text fields.
 
Sub Click(Source As Button)
'On Error Goto ProcessError
Dim session As New NotesSession
Dim ws As NotesUIWorkspace
Set ws = New NotesUIWorkspace
 
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
 
Dim doc As NotesDocument
Set doc = uidoc.Document
 
Dim body As NotesRichTextItem
 
Set body = doc.GetFirstItem ( "Body" )
 
If ( richTextFieldEmpty ( body ) ) Then
 
If ( uidoc Is Nothing ) Then
Else
Msgbox "Please enter the Content", MB_OK + MB_ICONSTOP, "Field Contains Incorrect Value"
Call uidoc.GoToField ( "Body" )
End If
 
validateRequiredFields = False
Exit Sub
 
Else
Print "Rich Text Field not empty"
End If
 
Exit Sub
ProcessError:
Msgbox Error & " - errno : " & Cstr(Err) & " @ line no - " & Cstr(Erl)
End Sub
 
Function richTextFieldEmpty ( rti As NotesRichTextItem ) As Boolean
 
Dim rtNav As NotesRichTextNavigator
 
On Error Goto errorHandler
 
richTextFieldEmpty = False
 
If ( rti Is Nothing ) Then
Print "Rich Text Field does not exist"
richTextFieldEmpty = True
Exit Function
End If
 
Set rtNav = rti.CreateNavigator
 
If ( rtNav.FindFirstElement ( RTELEM_TYPE_TABLE ) ) Then
Print "Table found in rich text field"
Exit Function
End If
 
If ( rtNav.FindFirstElement ( RTELEM_TYPE_TEXTRUN ) ) Then
Print "Text run found in rich text field"
Exit Function
End If
 
If ( rtNav.FindFirstElement ( RTELEM_TYPE_TEXTPARAGRAPH ) ) Then
Print "Text paragraph found in rich text field"
Exit Function
End If
 
If ( rtNav.FindFirstElement ( RTELEM_TYPE_DOCLINK ) ) Then
Print "Doclink found in rich text field"
Exit Function
End If
 
If ( rtNav.FindFirstElement ( RTELEM_TYPE_SECTION ) ) Then
Print "Section found in rich text field"
Exit Function
End If
 
If ( rtNav.FindFirstElement ( RTELEM_TYPE_TABLECELL ) ) Then
Print "Table cell found in rich text field"
Exit Function
End If
 
If ( rtNav.FindFirstElement ( RTELEM_TYPE_FILEATTACHMENT ) ) Then
Print "Attachment found in rich text field"
Exit Function
End If
 
If ( rtNav.FindFirstElement ( RTELEM_TYPE_OLE ) ) Then
Print "OLE object found in rich text field"
Exit Function
End If
 
richTextFieldEmpty = True
 
endOfCode:
Exit Function
 
errorHandler:
 
'displayError ( Getthreadinfo (1) )
 
Error Err, Error$ '-- Throw Error back to invoking code
 
Resume endOfCode
 
End Function

Nenhum comentário:

Postar um comentário