I have 20 fields (desc1, desc2, desc3........) that is hidden depending upon the user's input. Sample, if user inputs 5 then 5 desc1... fields will be displayed. Now, the problem I need to validate if all 5 desc and it must NOT be empty (the user can also pick 10 or more).
       Is there a a more efficient way to validate (maybe loop)?
Thank you!  
Who is Participating?
Joep8020Connect With a Mentor Commented:
Easiest way is good all @Formula language:

Let's assume the input field is called InputField and contains a numeric value; then use this formula in the input validation of the input field:
tList:=@Subset(desc1:desc2: desc3: desc4: desc5: desc6: desc7: desc8: desc9: desc10: desc11: desc12: desc13: desc14: desc15: desc16: desc17: desc18: desc19: desc20;tNr);
@If(@Elements(@Trim(tList))<tNr;@Failure("You need to give at " + @Text(tNR) + " descriptions";@Success);

Hope this will work for you...

Validation can be done in a loo if he field names are similarly names, which is always a good idea in your kind of scenario.

It can be done in the query save portion.

I'll find some code.

I hope this helps !
If felds are s1, s2 s..

In query save
' untested
Dim Nitem As NotesItem, Tstr2 As String
Dim DBE As NotesDocument
Dim ivalue  As Variant , v2 As integer
      Dim Dstr As String, Dstr1 As String, sdt as string
      Set dbe=source.Document      
      If source.IsNewDoc Then ' do any validation if needed
     for v2 = 1 to n  ' n is chosen and saved some where

        Sdt= "S" & v2  'set saved audit field
       Set Nitem = dbe.GetFirstItem( Sdt )
        ' validate here
        If not valid ' do your validation
           Continue = False
        end if
        ' set continue to false if not valid
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

you could also use  source.fieldGetText(SDT)  instead of the GetItem

I hope this helps !

cyleAuthor Commented:
Thank you, let me try it!
Hi cyle,
I usually add a multivalue field to the bottom of the form that lists or computes the fields that need to be validated.  So, in a simple form where I have three fields:  UserName, Address, Phone,  the multivalue field's (labeled validate) calculated value = "UserName":"Address":"Phone".

Then I can use the same validation script in the query close event in just about any form:

Sub Querysave(Source As Notesuidocument, Continue As Variant)
    Dim session As New NotesSession
    Dim db As NotesDatabase
    Set db = session.currentDatabase
    Dim doc As NotesDocument
    Set doc = source.document
    continue = True
    If source.EditMode Then
    End If
    Dim FieldList As Variant
    If Len(doc.Validate(0)) > 0 Then
        fieldList = doc.Validate
        Forall f In FieldList
            If Len(doc.GetItemValue(f)(0))<1 Then
                Msgbox "Sorry, the " + f + " field may not be blank",,"Validation Error!"
                continue = False
                Exit Sub
            End If
        End Forall
    End If
End Sub

Based on your problem, you can easily concatenate the formula on your form to include the selected fields:

F1:= @If(Select_1 !="";"UserName";"");
F2:= @If(Select_2 !="";"Address";"");
F3:= @If(Select_3 !="";"Phone";"");


Close!  But, missing a beat.   You would have to define the sets that are visible.

So, if when the user selects "1", desc1,desc2,desc3,desc4 are visible, then you need to validate those four fields.
If when the user selects "2", desc5, desc6, desc7,desc8 are visible, then validate those four fields.

Set1:=desc1:desc2: desc3: desc4;
Set2:=desc5: desc6: desc7: desc8;
Set3:=desc9: desc10: desc11: desc12;
Set4:=desc13: desc14: desc15: desc16;
Set5:=desc17: desc18: desc19: desc20;
REM "User Input is a List that returns a number This Value|1";

         @Failure("Sorry, Description fields may not be empty");
Oops, I put a "Validate" field, text, editable, hidden at the bottom of the form, and put the formula in the validation event.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.