Search documents between two dates in a view with a NotesViewNavigator

351 Views Asked by At

I try to get all the documents which has their creation date between two date (start and end).

I have a bug with sometimes dates. If the last category is the 15/01/2015, i have when i put start date or/and end date with 15/01/2015 : "object variable not set". I don't understand.

I have a view with in all my documents. This is a view categorized. I would like loog over this view with a notesviewnavigator.

When the creation date of my document is equal to or between the start or the final date, i put this document in my collection final. In the end of my program i put all in a folder and i display the view.

this is my code :

    Function RechercheDocParDate(dateDebut As String, dateFin As String, nomFolder1 As String, nomFolder2 As String, nomFolder3 As String, nomVue As String, numColonne As Integer) As Integer
' recherche les documents d'une vue en fonction de dates passées en paramètre pour les créer dans un folder privé

    Dim vueRech As NotesView    
    Dim j As Integer
    Dim collecEntryFinal As NotesViewEntryCollection
    Dim entry As NotesViewEntry
    Dim colonDate As String 
    Dim nbDocTrouve As Integer
    Dim flag As Boolean
    Dim nav As NotesViewNavigator
    Dim dbb As NotesDatabase    
    Dim Session As New NotesSession

    Set dbb = session.CurrentDatabase
    ' Récupération des données de la vue    
    Set vueRech = dbb.GetView(nomVue)   
    Call vueRech.Refresh    

    nbDocTrouve = 0

    ' a revoir : initialisation de la création d'entry
    ' création d'une collection d'entry (moins consommateur car le document n'est pas ouvert)   
    Set collecEntryFinal = vueRech.GetAllEntriesByKey("_gdfgdfg")   
    j = 1
    flag = True     

    ' création d'un navigateur de catégorie d'entry
    Set nav = vueRech.CreateViewNav
    Set entry = nav.GetFirst

'   si on n'est pas rendu à la fin de la vue (penser aux hors catégories)   
    While ( (Not (entry Is Nothing) ) And ( flag = True ) )  
'       si c'est bien une categorie
        If entry.IsCategory Then            
            'récupère la colonne de date 
            colonDate =  entry.ColumnValues(numColonne) 
            If ( colonDate >= dateDebut ) Then
                If  ( colonDate > dateFin ) Then                    
                    flag = False
                Else    
                    Set entry = nav.GetNext(entry)
                    's'il y a des documents
                    While ( (Not (entry Is Nothing) ) And (entry.IsDocument) )
                        'recupere les documents de la catégorie                     
                        Call collecEntryFinal.AddEntry(entry)                   
                        nbDocTrouve = nbDocTrouve + 1           
                        Set entry = nav.GetNext(entry) 
                        '//ALERT
                        ' it finds the documents but in the end of the list of document it crashes here
                        '//ALERT

                    Wend  
                    Set entry = nav.GetPrev(entry)      
                    End If              
                End If
            Else            
                'recupere les documents hors catégorie
                While ( (Not (entry Is Nothing) ) And (entry.IsDocument) )      
                    Call collecEntryFinal.AddEntry(entry)                   
                    nbDocTrouve = nbDocTrouve + 1       
                    Set entry = nav.GetNext(entry)      
                Wend    
            End If
            Set entry = nav.GetNextCategory(entry)  
        Wend    

        'on crée le dossier  privé pour l'utilisateur
        'si on trouve des résultats ils sont ajoutés dans le folder
        If Not Isempty(collecEntryFinal)  Then
            If nomFolder1 <> ""  Then               
                collecEntryFinal.PutAllInFolder(nomFolder1) 
            End If
            If nomFolder2 <> ""  Then       
                collecEntryFinal.PutAllInFolder(nomFolder2) 
            End If
            If nomFolder3 <> ""  Then           
                collecEntryFinal.PutAllInFolder(nomFolder3) 
            End If
        End If  
        Call vueRech.Refresh
        RechercheDocParDate = nbDocTrouve

    End Function

When i do a step by step i understand it but at the end of the while (look in the code, i put an alert)

1

There are 1 best solutions below

0
On BEST ANSWER

Not sure if you're still having this problem, but for future reference the solution is simple.

You have a nested while/wend loop to cycle through the documents in each category of your navigator. This internal while/wend can exhaust all the available documents in the navigator, resulting in "entry" becoming "nothing". You then call either nav.getPrev() or nav.GetNextCategory() outside this nested while, causing your exception, since both nav.getPrev() nav.GetNextCategory() cannot be called using an undefined, or "nothing", parameter.

The documentation concerning the "entry" parameter for GetNextCategory explicitly states that "If you specify Nothing, this method generates an error."

The documentation concerning the "entry" parameter for GetPrev states the same.

Code to fix your problem:

Function RechercheDocParDate(dateDebut As String, dateFin As String, nomFolder1 As String, nomFolder2 As String, nomFolder3 As String, nomVue As String, numColonne As Integer) As Integer
    ' recherche les documents d'une vue en fonction de dates passées en paramètre pour les créer dans un folder privé

    Dim vueRech As NotesView    
    Dim j As Integer
    Dim collecEntryFinal As NotesViewEntryCollection
    Dim entry As NotesViewEntry
    Dim colonDate As String 
    Dim nbDocTrouve As Integer
    Dim flag As Boolean
    Dim nav As NotesViewNavigator
    Dim dbb As NotesDatabase    
    Dim Session As New NotesSession

    Set dbb = session.CurrentDatabase
    ' Récupération des données de la vue    
    Set vueRech = dbb.GetView(nomVue)   
    Call vueRech.Refresh    

    nbDocTrouve = 0

    ' a revoir : initialisation de la création d'entry
    ' création d'une collection d'entry (moins consommateur car le document n'est pas ouvert)   
    Set collecEntryFinal = vueRech.GetAllEntriesByKey("_gdfgdfg")   
    j = 1
    flag = True     

    ' création d'un navigateur de catégorie d'entry
    Set nav = vueRech.CreateViewNav
    Set entry = nav.GetFirst

    '   si on n'est pas rendu à la fin de la vue (penser aux hors catégories)   
    While ( (Not (entry Is Nothing) ) And ( flag = True ) )  
    '       si c'est bien une categorie
        If entry.IsCategory Then            
            'récupère la colonne de date 
            colonDate =  entry.ColumnValues(numColonne) 
            If ( colonDate >= dateDebut ) Then
                If  ( colonDate > dateFin ) Then                    
                    flag = False
                Else    
                    Set entry = nav.GetNext(entry)
                    's'il y a des documents
                    While ( (Not (entry Is Nothing) ) And (entry.IsDocument) )
                        'recupere les documents de la catégorie                     
                        Call collecEntryFinal.AddEntry(entry)                   
                        nbDocTrouve = nbDocTrouve + 1           
                        Set entry = nav.GetNext(entry) 
                    Wend
                    ' ---FIRST FIX HERE---
                    If (Not (entry Is Nothing) ) Then
                        Set entry = nav.GetPrev(entry)
                    End If
                End If              
            End If
        Else            
            'recupere les documents hors catégorie
            While ( (Not (entry Is Nothing) ) And (entry.IsDocument) )      
                Call collecEntryFinal.AddEntry(entry)                   
                nbDocTrouve = nbDocTrouve + 1       
                Set entry = nav.GetNext(entry)      
            Wend    
        End If
        ' ---SECOND FIX HERE---
        If (Not (entry Is Nothing) ) Then
            Set entry = nav.GetNextCategory(entry)  
        End If
    Wend    

    'on crée le dossier  privé pour l'utilisateur
    'si on trouve des résultats ils sont ajoutés dans le folder
    If Not Isempty(collecEntryFinal)  Then
        If nomFolder1 <> ""  Then               
            collecEntryFinal.PutAllInFolder(nomFolder1) 
        End If
        If nomFolder2 <> ""  Then       
            collecEntryFinal.PutAllInFolder(nomFolder2) 
        End If
        If nomFolder3 <> ""  Then           
            collecEntryFinal.PutAllInFolder(nomFolder3) 
        End If
    End If  
    Call vueRech.Refresh
    RechercheDocParDate = nbDocTrouve

End Function

Note there are two changes, both are simple tests for Nothing. This should fix your issue or similar issues. Just remember that none of the Navigator navigation methods accept Nothing, and you should be able to avoid similar problems in the future.