When selection taken...

Hello, I have a form with embedded view, linked to it's own form... When I want to add an entry by using the following code attached, it gives me my selection to work from. This works 100% and I would like to take it one step further...

If I have in my selection 3 items to choose from, I pick a selection and it adds it to my embedded view, I click on the add function again, it should not show me the one I have just selected, only the remaining ones that are left.

This way I will make sure I dont have any duplications  in my embeded view, as there cant be any.
car701015Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

car701015Author Commented:
just in case code did not show up

Sub Click(Source As Button)
      
      Dim Session As New NotesSession
      Dim WorkSpace As New NotesUIWorkspace
      Dim uiDoc As NotesUIDocument
      Dim srcDoc As NotesDocument
      
      Set srcDoc = WorkSpace.CurrentDocument.Document
      Set uiDoc = Workspace.CurrentDocument
      
      Dim CurDatabase As NotesDatabase
      
      Set CurDatabase = session.CurrentDatabase
      
      Dim dbDoc As NotesDocument
      Set dbDoc = CurDatabase.CreateDocument
      
      Dim Ref_Number As String
      Dim EI_Reference As String
      
      Ref_Number = srcdoc.GetFirstItem("dro_number").Text
      EI_Reference = srcdoc.GetFirstItem("dro_eiref").Text
      
      ' Need to go and get a list of container numbers for the selected Shipment
      '---------------------------------------------------------------------------------------------------------------------------
      Dim eDocs As NotesDocumentCollection
      Dim eDoc As NotesDocument
      Dim Containers As String
      
      Set eDocs = CurDatabase.Search( { Form = "Form" & ei_ref = "} & EI_Reference & {"} , Nothing , 0 )
      Set eDoc = eDocs.GetFirstDocument
      
      While Not(eDoc Is Nothing)
            If eDoc.HasItem("container_numbers") Then
                  Containers = Containers & ";" & eDoc.GetFirstItem("container_numbers").Text
            End If
            Set eDoc = eDocs.GetNextDocument(eDoc)
      Wend
      
      ' Get rid of Leading SemiColon
      If Left(Containers,1) = {;} Then
            Containers = Mid(Containers,2)
      End If
      '---------------------------------------------------------------------------------------------------------------------------
      
      If Trim(Containers) = "" Then
            Msgbox "No Containers to pick from"
            Exit Sub
      End If
      
      ' Need to prompt the user to select a Container from the list
      '---------------------------------------------------------------------------------------------------------------------------
      Dim PickResult As Variant
      
      PickResult = Workspace.Prompt(4,"Container Selection","Please select one Conatiner","",Split(Containers,{;}))
      '---------------------------------------------------------------------------------------------------------------------------
      
      If Isempty(PickResult) Then
            Msgbox "You did not select a Container"
      Else
            Call dbDoc.ReplaceItemValue("Form", "Delivery Order Item")
            Call dbDoc.ReplaceItemValue("dro_number", Ref_Number )
            Call dbDoc.ReplaceItemValue("ctnr_container_number",PickResult)
            
            If WorkSpace.DialogBox("Delivery Order Item",True,True,False,False,False,False,"Enter Container Details",dbDoc) Then
                  Call dbDoc.Save(True,False,True)
                  Call Workspace.CurrentDocument.Refresh
            End If
      End If
      
End Sub
0
Sjef BosmanGroupware ConsultantCommented:
If I understand you correctly (I didn't read the code yet), you add a document but you want it excluded from an embedded view? Well, an embedded view is just a normal view: it has a SELECT statement that is fixed. If you want documents not to appear in a view, the SELECT statement should exclude them (or not include).

Or is it not really an embedded view but something that you developed yourself?

And why not a Prompt with PROMPT_OKCANCELLISTMULT (7) ?

You could save the containers selected in a global form variable. But what happens if the main document is reopened and the same button is clicked again? Would it show the same containers again? If you really want to exclude these documents, you have to adapt the Search. By the way, the Search works very well on a small database, but is searches a database sequentially so it is very slow on large databases. Better use a (hidden) view: MUCHO faster.

PS Just a coding tip:

      While Not(eDoc Is Nothing)
            If eDoc.HasItem("container_numbers") Then
                  Containers = Containers & ";" & eDoc.GetFirstItem("container_numbers").Text
            End If
            Set eDoc = eDocs.GetNextDocument(eDoc)
      Wend
     
      ' Get rid of Leading SemiColon
      If Left(Containers,1) = {;} Then
            Containers = Mid(Containers,2)
      End If

Consider this alternative:
      Dim sep As String
      sep= ""
      Do Until eDoc Is Nothing
            If eDoc.HasItem("container_numbers") Then
                  Containers = Containers & sep & eDoc.GetFirstItem("container_numbers").Text
                  sep= ";"
            End If
            Set eDoc = eDocs.GetNextDocument(eDoc)
      Loop
0
mbonaciCommented:
You can build the list of the values taken from your embedded view's documents, container_numbers field.
Then you check before adding to Containers variable in your while loop.
Something like the code bellow:
Dim existingContainers List As String

get the view
get first document in a view

until document is nothing
  existingContainers( document.Containers(0) ) = ""  'add to list
  get next document in a view
loop


'then in your while loop

      Dim tmpStr As String

      While Not(eDoc Is Nothing)
            If eDoc.HasItem("container_numbers") Then

                  tmpStr = eDoc.container_numbers(0)
                  If Not IsElement( existingContainers( tmpStr ) ) Then
                       Containers = Containers & ";" & tmpStr
                  End If

            End If
            Set eDoc = eDocs.GetNextDocument(eDoc)
      Wend



If container_numbers is multivalue field, then you need to check each field's value against the list, in a loop, like this:

Forall elem In eDoc.container_numbers
    If Not IsElement( existingContainers( elem ) ) Then
        Containers = Containers & ";" & elem
    End If

End Forall

Open in new window

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

car701015Author Commented:
I cant get this right :( grrrr :) sometimes so frustrating...

sjef - I have used your Consider this alternative: code... much less than mine :)

mbonaci... :( is it wekend yet?

0
mbonaciCommented:
Where is the problem?
0
car701015Author Commented:
Not sure I am with this section?

get the view
get first document in a view

My embedded view or must I create ANOTHER view?
0
mbonaciCommented:
Your embedded view. You want to build the list of current entries in embedded view so that you can exclude them from the prompt list, right?

Fill the list like this:
Dim existingContainers List As String
Dim eView As NotesView

Set eView = db.getView( viewName )
Set curDoc = eView.GetFirstDocument

Do Until curDoc Is Nothing
    existingContainers( document.Containers(0) ) = ""  'add to list
    Set curDoc = eView.GetNextDocument( curDoc )
Loop

'ask when you get stuck again...

Open in new window

0
mbonaciCommented:
Sorry, I copied from above, it's not
   existingContainers( document.Containers(0) ) = ""  'add to list

but
   existingContainers( curDoc.Containers(0) ) = ""  'if Containers is the name of the field
0
car701015Author Commented:
Hi,

Sorry, been a long weekend...

I did some changes and suggested changes and I get the following

Variant does not contain object... hahaha, maybe I just lots it completele... anyhow, here's the revised codes...

Sub Click(Source As Button)
      
      Dim Session As New NotesSession
      Dim WorkSpace As New NotesUIWorkspace
      Dim uiDoc As NotesUIDocument
      Dim srcDoc As NotesDocument
      
      Set srcDoc = WorkSpace.CurrentDocument.Document
      Set uiDoc = Workspace.CurrentDocument
      
      Dim CurDatabase As NotesDatabase
      
      Set CurDatabase = session.CurrentDatabase
      
      Dim dbDoc As NotesDocument
      Set dbDoc = CurDatabase.CreateDocument
      
      Dim Ref_Number As String
      Dim EI_Reference As String
      
      Ref_Number = srcdoc.GetFirstItem("dro_number").Text
      EI_Reference = srcdoc.GetFirstItem("dro_eiref").Text
      
      '******************************************************************************************
      ' Need to go and get a list of container numbers for the selected Shipment
      '******************************************************************************************
      Dim eDocs As NotesDocumentCollection
      Dim eDoc As NotesDocument
      Dim Containers As String
      
      Set eDocs = CurDatabase.Search( { Form = "Form" & ei_ref = "} & EI_Reference & {"} , Nothing , 0 )
      Set eDoc = eDocs.GetFirstDocument
      
      Dim existingContainers List As String
      Dim eView As NotesView
      Dim curDoc As Variant
      Dim DB As Variant
      
'&&&
      
      Set eView = db.getView( "Delivery Order Items" )
      Set curDoc = eView.GetFirstDocument
      
      Do Until curDoc Is Nothing
            existingContainers( curDoc.Containers(0) ) = ""  'if Containers is the name of the field
            Set curDoc = eView.GetNextDocument( curDoc )
      Loop
      '&&&
      
      
      Dim sep As String
      sep= ""
      
      Do Until eDoc Is Nothing
            If eDoc.HasItem("container_numbers") Then
                  Containers = Containers & sep & eDoc.GetFirstItem("container_numbers").Text
                  sep= ";"
            End If
            Set eDoc = eDocs.GetNextDocument(eDoc)
      Loop
      '******************************************************************************************
      
      If Trim(Containers) = "" Then
            Msgbox "No Containers to pick from"
            Exit Sub
      End If
      
      '******************************************************************************************
      ' Need to prompt the user to select a Container from the list
     '******************************************************************************************
      Dim PickResult As Variant
      
      PickResult = Workspace.Prompt(4,"Container Selection","Please select one Conatiner","",Split(Containers,{;}))
      
      If Isempty(PickResult) Then
            Msgbox "You did not select a Container"
      Else
            Call dbDoc.ReplaceItemValue("Form", "Delivery Order Item")
            Call dbDoc.ReplaceItemValue("dro_number", Ref_Number )
            Call dbDoc.ReplaceItemValue("ctnr_container_number",PickResult)
            
            If WorkSpace.DialogBox("Delivery Order Item",True,True,False,False,False,False,"Enter Container Details",dbDoc) Then
                  Call dbDoc.Save(True,False,True)
                  Call Workspace.CurrentDocument.Refresh
            End If
      End If
      
End Sub

0
mbonaciCommented:
OK, you filled the list, but you haven't checked whether the containers you're putting in the prompt are already in the list (view):
Dim tmpStr As String

      Do Until eDoc Is Nothing
            If eDoc.HasItem("container_numbers") Then

                  tmpStr = eDoc.container_numbers(0)
                  If Not IsElement( existingContainers( tmpStr ) ) Then
                       Containers = Containers & ";" & tmpStr
                  End If

            End If
            Set eDoc = eDocs.GetNextDocument(eDoc)
      Loop

Open in new window

0
mbonaciCommented:
One more thing, to find out where and which error occurs add error handling to your code:

First line of code (above Dim Session As New NotesSession) should be:

    On Error Goto ErrHandler


And last code section (above End Sub) should be:

leave:
    Exit Sub
ErrHandler:
    Msgbox "Error " & Cstr( Err ) & ": " & Error$ & " in line " & Cstr( Erl )
    Resume leave
End Sub


Then we'll handle that error message you're getting...
0
car701015Author Commented:
Cool, I am learning something today :)

Error 183: Variant does not contain an object in line 58...

Set eView = db.getView( "Delivery Order Items" )
0
mbonaciCommented:
Replace
    db
with
    CurDatabase
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
car701015Author Commented:
Change worked to bring up the list, however, I selected the first one and then went back, list remains the same.
0
mbonaciCommented:
Can you send me a empty db with embedded view and form included so I can check that.
You have e-mail in my profile.
0
car701015Author Commented:
done...
0
car701015Author Commented:
Fantastic! This will save my users so much time and the data integrity will be spot on... MUCH APPRECIATED!!!!!
0
mbonaciCommented:
OK, here's the code with error "Illegal function call in line 57" resolved (for others):
Sub Click(Source As Button)
	On Error Goto ErrHandler
	Dim Session As New NotesSession	
	Dim WorkSpace As New NotesUIWorkspace
	Dim CurDatabase As NotesDatabase
	Dim eView As NotesView
	Dim eDocs As NotesDocumentCollection, existingCol As NotesDocumentCollection
	Dim srcDoc As NotesDocument, dbDoc As NotesDocument
	Dim eDoc As NotesDocument, curDoc As NotesDocument
	Dim uiDoc As NotesUIDocument
	Dim existingContainers List As String
	Dim Ref_Number As String, EI_Reference As String, Containers As String, tmpStr As String
	Dim tmpArr As Variant, PickResult As Variant
	Const sep$ = "; "
	
	Set CurDatabase = session.CurrentDatabase	
	Set uiDoc = Workspace.CurrentDocument
	Set srcDoc = uiDoc.Document
	Set dbDoc = CurDatabase.CreateDocument
	
	Ref_Number = srcdoc.GetFirstItem("dro_number").Text
	EI_Reference = srcdoc.GetFirstItem("dro_eiref").Text
	
	'******************************************************************************************
	' Need to go and get a list of container numbers for the selected Shipment
	'******************************************************************************************
	
	'first put all dro_numbers from the embedded view in a list
	Set eView = CurDatabase.getView( "Delivery Order Items" )
	Set existingCol = eView.GetAllDocumentsByKey( srcDoc.dro_number(0) ) 'get docs seen in embedded view from your doc
	
	Set curDoc = existingCol.GetFirstDocument	
	Do Until curDoc Is Nothing
		existingContainers( curDoc.ctnr_container_number(0) ) = ""  'if Containers is the name of the field
		Set curDoc = existingCol.GetNextDocument( curDoc )
	Loop
	
	
	Set eDocs = CurDatabase.Search( { Form = "Form" & ei_ref = "} & EI_Reference & {"} , Nothing , 0 )
	If eDocs Is Nothing Then Exit Sub
	If eDocs.Count > 0 Then
		
		Set eDoc = eDocs.GetFirstDocument
		Do Until eDoc Is Nothing
			If eDoc.HasItem("container_numbers") Then
				tmpStr = eDoc.container_numbers(0)
				tmpArr = Split( tmpStr, sep )
				Forall elem In tmpArr	'for each number in container_numbers check whether it's in our list
					If Not Iselement( existingContainers( elem ) ) Then
						Containers = Containers & elem & sep		'add to prompt only if it is not in a list
					End If				
				End Forall
			End If
			Set eDoc = eDocs.GetNextDocument(eDoc)
		Loop
		
		If Len( containers ) > 2 Then
			Containers = Left( Containers, Len( Containers ) - 2 )
		End If
      '******************************************************************************************
	Else
		
		Msgbox "No Containers to pick from"
		Exit Sub
	End If
	
      '******************************************************************************************
      ' Need to prompt the user to select a Container from the list
     '******************************************************************************************
	
	PickResult = Workspace.Prompt(4,"Container Selection","Please select one Conatiner","",Split(Containers,{; }))
	
	If Isempty(PickResult) Then
		Msgbox "You did not select a Container"
	Else
		Call dbDoc.ReplaceItemValue("Form", "Delivery Order Item")
		Call dbDoc.ReplaceItemValue("dro_number", Ref_Number )
		Call dbDoc.ReplaceItemValue("ctnr_container_number",PickResult)
		
		If WorkSpace.DialogBox("Delivery Order Item",True,True,False,False,False,False,"Enter Container Details",dbDoc) Then
			Call dbDoc.Save(True,False,True)
			Call Workspace.CurrentDocument.Refresh
		End If
	End If
	
leave:
	Exit Sub
ErrHandler:
	Msgbox "Error " & Cstr( Err ) & ": " & Error$ & " in line " & Cstr( Erl )
	Resume leave
End Sub

Open in new window

0
mbonaciCommented:
To figure out exactly what happens in the code I suggest you:
 - turn LotusScript debugger on
 - open your database
 - open one Delivery order document (preferably with one or more order items already selected)
 - click on new Add button, we've just created
 - use "Step into" to go through code line by line
 - examine what happens with variables in lower pane after each line is executed

That's the fastest way to analyze (and learn) the code
0
car701015Author Commented:
I HAVE LEARNED a LOT, NO MORE THAN A LOT, THANKS FOR THE HELP, SHOULD HAVE SELECTED THE RIGHT COMMENT TO APPROVE, can see why you are the GURU :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

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.