Deleting selected line items with fields in a table containing multi values

I am trying to delete a selected line items - I have 4 multi value fields in a table and when the user selects a line item I need to remove only the selected line values. The code I have now is removing all line items and I am not sure how to make a prompt or picklist for the selected item and code it specifically to be removed. I have been trying everything but nothing works. All help is appreciated. Here is my code below:

Sub Click(Source As Button)

Dim ws As New NotesUIWorkSpace

Dim uidoc As NotesUIDocument

Dim docCurr As NotesDocument

Dim strInvcNo As String

Dim strInvcDtOut As String

Dim strInvcNoOut As String

Dim strInvcCCOut As String

Dim strInvcDlrsOut As String

Dim varInvcDt As Variant

Dim varResponse As Variant



On Error Goto errHandle



Set uidoc = ws.CurrentDocument



 'Get number of records to delete, from count of new component codes

intCCCtr = Cint(uidoc.FieldGetText("SR_NCCCount_exist"))	

Redim strCompCodes(1 To intCCCtr) As String

strCCIn = uidoc.FieldGetText("SR_NCCCount_exist")



If varError Then Exit Sub	

varInvcDt = uidoc.FieldGetText("SR_InvoiceDt")

strInvcNo = uidoc.FieldGetText("SR_InvoiceNo")

For intLoopCtr = 1 To intCCCtr

	If uidoc.FieldGetText("SR_InvoiceDt") <> "" Then uidoc.FieldSetText "SR_InvoiceDt",""

	If uidoc.FieldGetText("SR_InvoiceNo") <> "" Then uidoc.FieldSetText "SR_InvoiceNo", ""

	If uidoc.FieldGetText("SR_InvoiceCompCodes") <> "" Then uidoc.FieldSetText "SR_InvoiceCompCodes", ""

	If uidoc.FieldGetText("SR_InvoiceDollars") <> "" Then uidoc.FieldSetText "SR_InvoiceDollars", ""		

	uidoc.refresh

	

	Exit Sub

errHandle:

	Dim strErrText As String

	strErrText = "An error occurred in the CLICK event of the Delete Invoice Data Button.  Err no.: " + Cstr(Err) + " -- " + Error

	Messagebox strErrText, 0+16+0+0, "ERROR!"

	Exit Sub

Next

End Sub])

Subject: deleting selected line items with fields in a table containing multi values

Mary,

I think I would use backend doc, not frontend uidoc. I would create an array for each of my fields … for example

dim SR_InvoiceDt () as string

dim k as integer ’ counter for array

tSR_InvoiceDt = doc.SR_InvoiceDT

dim i as integer ’ generic counter

i = 0

do while i <= ubound ( tSR_InvoiceDt )

if i <> magicNumber then

redim preserve SR_InvoiceDt ( k )

SR_InvoiceDt ( k ) = tSR_InvoiceDt ( i )

k = k + 1

end if

i = i + 1

loop

doc.SR_InvoiceDt = SR_InvoiceDt

hope that helps,

raphael

Subject: RE: deleting selected line items with fields in a table containing multi values

Raphael,

Thanks for the help…but the code still does not allow for the user to select a line item. I placed the following code in my button and nothing happens

Sub Click(Source As Button)

Dim ws As New NotesUIWorkSpace

Dim session As New NotesSession

Dim DB As NotesDatabase

Dim Doc As NotesDocument

Set DB = session.CurrentDatabase

Set Doc = New NotesDocument (DB) 	

Dim magicNumber As Variant

Dim tSR_InvoiceDt As Variant

Dim SR_InvoiceDt As Variant	

Dim k As Integer ' counter for array



tSR_InvoiceDt = doc.SR_InvoiceDT





Dim i As Integer ' generic counter 

i = 0

Do While i <= Ubound ( tSR_InvoiceDt )

	If i <> magicNumber Then

		Redim Preserve SR_InvoiceDt ( k )

		SR_InvoiceDt ( k ) = tSR_InvoiceDt ( i )

		k = k + 1

	End If

	

	i = i + 1

Loop



doc.SR_InvoiceDt = SR_InvoiceDt

End Sub

Subject: RE: deleting selected line items with fields in a table containing multi values

Mary,

To access the backend doc, you don’t create a new doc, but instead set doc = uidoc.Document. This will give you the backend doc. At that point you can do what Raphael states, and then call uidoc.Reload to see the changes to the backend in the front end.

However, I would warn you that if you have a table with four specific multivalue fields, you need to make absolutely sure that position 1 of field 1 matches with position 1 of field 2 and so on. There is a possibility that your multivalue fields can get out of sync.

The way i combat that is to create a hidden multi-value text field and concatenate all of my multi value field values into one string value using a separator of some kind (i am partial to the pound sign, but any separator will work.) I can then use formula language to separate them out for display purposes using the @Left and @Right commands. I then define two custom built user classes–one to contain the data and have it easily accessible and another to parse the hidden field and populate the user defined objects accordingly.

Take it from someone who knows…these fields can get out of sync easily. Until I figured out how to use classes, these sort of tables NEVER worked for me.

brandt

Subject: RE: deleting selected line items with fields in a table containing multi values

Ok, I guess I should have mentioned I am relatively new to Lotus Script. But, I have revised the code and tested it in debugger. While I can see it looping thru all lines in the multivalue field. I still need a dialog box to allow the user to select the line item to be deleted and delete only that line. Please see the revised code below:

Sub Click(Source As Button)

Dim ws As New NotesUIWorkSpace

Dim session As New NotesSession

Dim DB As NotesDatabase

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Set DB = session.CurrentDatabase

Set uidoc = ws.CurrentDocument

Set doc = uidoc.document 

Dim magicNumber As Variant

Dim tSR_InvoiceDt As Variant

Dim SR_InvoiceDt As Variant 

Dim k As Integer ' counter for array



tSR_InvoiceDt = doc.SR_InvoiceDT





Dim i As Integer ' generic counter 

i = 0

Do While i <= Ubound ( tSR_InvoiceDt )

	If i <> magicNumber Then

	'	Redim Preserve SR_InvoiceDt ( k )

		Redim  SR_InvoiceDt ( k )

		SR_InvoiceDt ( k ) = tSR_InvoiceDt ( i )

		k = k + 1

	End If

	

	i = i + 1

Loop



doc.SR_InvoiceDt = SR_InvoiceDt

Call uidoc.Reload 

End Sub

Subject: RE: deleting selected line items with fields in a table containing multi values

Mary,

what you are looking for is the NotesUIWorkspace method DialogBox. I would check the designer help on its use…

brandt