Form Help

Hi All

I am trying to recreate the fuctionality of an Access Data Subform in a notes form. What I have is a subform with the following fields Edit Date : Edit Name : Contractor Name : Contractor Info. The Edit Date and Name are generated automatically. What I would like is a button that when pressed creates a new line and allows you to enter the Contractor name and info, with the time it was created (Edit Date) and who it was created by (Edit Name). This section will probably contain a lot of entries. Any help is appreciated.

Regards

Djbell

Subject: Form Help

Why are you relying on manual entry of the name instead of just capturing the username of the person editing the document?

I have a number of applicatiosn where I call this script library subroutine as part of the QuerySave event:

strFieldName is the name of the multivalue field to be changed (I use it this way for code protability and the ability to use it for multiple fields in a workflow application).

Sub AddToAuditHistory( message As String, CurrDoc As NotesDocument, strFieldName As String)

Dim session As New NotesSession

Dim n As Integer

Dim anyElem As Integer

Dim vHistory As Variant

Dim strHistoryField As String

Dim outList() As String

Dim abbrevname$

anyElem=False

abbrevname=session.CreateName

 (session.Username).Abbreviated

vHistory=currdoc.GetItemValue(strFieldName)

n=0

Forall Elem In vHistory

anyElem=True

n=n+1

End Forall

If Not anyElem Then

outlist(0)= Format(Now,"mm/dd/yyyy hh:nn:ss 

  AM/PM") + " - " + message + " by "  +

  abbrevname   

Else

Redim outlist(n)

outlist(0)= Format(Now,"mm/dd/yyyy hh:nn:ss

  AM/PM") + " - " + message + " by "  +

 abbrevname 

n=1

Forall Elem In vHistory

outlist(n) = Elem

n=n+1

End Forall

End If

Call CurrDoc.ReplaceItemValue(strFieldname,

outList)

End Sub

Subject: RE: Form Help

Hi File Save

Thanks for the reply, the Date and Username is automatically generated by @now and @Name([CN];@UserName) it is the contractor name and contractor information that must be manually inputed. On my main form I have a contractor subform that when the Add contractor button is pressed then it allows you to add a contractor name and informtion. This will then be saved, then when the Add contractor Button is pressed again it will allow you to put a new contractor name and info. Also the Contractor info must allow you to go back and edit this field only, preferably a small button next to each line.

Regards

Douglas Bell

Subject: RE: Form Help

I misinterpreted your question, sorry.

You can either do a dynamic table or just create a contractor profile document and include an embedded view of these documents. Much easier, cleaner and less code overhead.

Subject: As long as you don’t get more than a about a hundred entries, you can use Multi-value Computed Main fields…

some sample code from an “Add” button:tbRet := @DialogBox(“YourBox”; [AutoHorzFit] : [AutoVertFit]);
@If(tbRet = 0; @Return(“”); “”);
@If(“” != DYourField1 : DYourField2; “”; @Return(“”));
REM;
tbNum := @If(YourField1 = “”; 1; @Elements(YourField1) + 1);
REM;
FIELD YourField1 := @If(tbNum = 1; DYourField1; YourField1 : DYourField1);
FIELD YourField2 := @If(tbNum = 1; DYourField2; YourField2 : DYourField2);
REM;
FIELD DYourField1 := @DeleteField;
FIELD DYourField2 := @DeleteField;
REM;
@Command([ViewRefreshFields])

Subject: RE: As long as you don’t get more than a about a hundred entries, you can use Multi-value Computed Main fields…

Hi Bill

Thanks for the reply, how do I go back and edit one of the fields without effecting the rest of the entries, I want the CreatedDate the Username and Contractorname to be uneditable once entered but I want the Contractorinfo to be updated if any information changes with that contractor.

Regards

Douglas Bell

Subject: You should be able to figure out any additional code you need from this…

The DYourField’s represent the fields on the dialog box.

tbNum := @If(YourField1 = “”; @Return(@Prompt([OK]; “No Items Found”; “You have not entered any items in the table yet (therefore, there’s nothing there to edit).”)); @Elements(YourField1));
REM;
tbL1 := “0” : “1” : “2” : “3” : “4” : “5” : “6” : “7” : “8” : “9”;
tbL2 := @Subset(tbL1 *+ tbL1; -99);
tbNumList := @Subset(tbL2; tbNum);
REM;
tbChoices := tbNumList + “. " + YourField1;
tbChoice := @Prompt([OKCancelList]; “Select Item”; “Please select the item you would like to update:”; @Subset(tbChoices; 1); tbChoices);
@If(tbChoice = 1; @Return(@Prompt([OK]; “No Item Selected”; “You did not select an item. This process has been stopped.”)); “”);
REM;
tbLNum := @Member(tbChoice; tbChoices);
tbIsFirst := tbLNum = 1;
tbIsLast := tbLNum = tbNum;
tbIsOnly := tbNum = 1;
REM;
FIELD DYourField1 := @Subset(@Subset(YourField1; tbLNum); -1);
FIELD DYourField2 := @Subset(@Subset(YourField2; tbLNum); -1);
REM;
tbRet := @DialogBox(“YourDialog”; [AutoHorzFit] : [AutoVertFit]);
@If(tbRet = 0; @Return(”“); “”);
@If(”" != DYourField1 : DYourField2; “”; @Return(“”));
REM;
FIELD YourField1 := @If(tbIsOnly; DYourField1; tbIsFirst; DYourField1 : @Subset(YourField1; 1 - tbNum); tbIsLast; @Subset(YourField1; tbNum - 1) : DYourField1; @Subset(YourField1; tbLNum - 1) : DYourField1 : @Subset(YourField1; tbLNum - tbNum));
FIELD YourField2 := @If(tbIsOnly; DYourField2; tbIsFirst; DYourField2 : @Subset(YourField2; 1 - tbNum); tbIsLast; @Subset(YourField2; tbNum - 1) : DYourField2; @Subset(YourField2; tbLNum - 1) : DYourField2 : @Subset(YourField2; tbLNum - tbNum));
REM;
FIELD DYourField1 := @DeleteField;
FIELD DYourField2 := @DeleteField;
REM;
@Command([ViewRefreshFields])

Subject: RE: You should be able to figure out any additional code you need from this…

Brilliant, Thank You Bill

Just one little query is it possible for the text to allign properly if there is a description that covers more than one line? For Example

At the moment my results look like the below (Sorry had to use full stops instead of spaces):-

Roof Ltd…Good Contractor

Walls Ltd…This contractor is not

Windows Ltd…as good as roof ltd.

…The Best contractor.

Is it possible to get it formated like this:-

Roof Ltd…Good Contractor

Walls Ltd…This contractor is not

…as good as roof ltd.

Windows Ltd…The Best contractor.

Again Thankyou Bill, this is superb, if the formatting cant be done then I will just increase the length of the table and limit the amout of description that can be put in.

Regards

Douglas Bell

Subject: RE: You should be able to figure out any additional code you need from this…

Hi Bill

Sorry about this, I dont want to become a nuissance. I added another two fields called Cuname and Cudate which are computed fields on the DialogBox form, I modified the Add button code to this:-

tbRet := @DialogBox(“Contract”; [AutoHorzFit] : [AutoVertFit]);

@If(tbRet = 0; @Return(“”); “”);

@If(“” != Cnamedb : Cinfodb : Cdate : Cuname; “”; @Return(“”));

REM;

tbNum := @If(Cname = “”; 1; @Elements(Cname) + 1);

REM;

FIELD Cname := @If(tbNum = 1; Cnamedb; Cname : Cnamedb);

FIELD Cinfo := @If(tbNum = 1; Cinfodb; Cinfo : Cinfodb);

FIELD Cdate := @If(tbNum = 1; Cdatedb; Cdate : Cdatedb);

FIELD Cuname := @If(tbNum = 1; Cunamedb; Cuname : Cunamedb);

REM;

FIELD Cnamedb := @DeleteField;

FIELD Cinfodb := @DeleteField;

FIELD Cdatedb := @DeleteField;

FIELD Cunamedb := @DeleteField;

REM;

@Command([ViewRefreshFields])

and modified the edit button to this:-

tbNum := @If(Cname = “”; @Return(@Prompt([Ok]; “No Items Found”; “You have not entered any items in the table yet (therefore, there’s nothing there to edit).”)); @Elements(Cname));

REM;

tbL1 := “0” : “1” : “2” : “3” : “4” : “5” : “6” : “7” : “8” : “9”;

tbL2 := @Subset(tbL1 *+ tbL1; -99);

tbNumList := @Subset(tbL2; tbNum);

REM;

tbChoices := tbNumList + ". " + Cname;

tbChoice := @Prompt([OkCancelList]; “Select Item”; “Please select the item you would like to update:”; @Subset(tbChoices; 1); tbChoices);

@If(tbChoice = 1; @Return(@Prompt([Ok]; “No Item Selected”; “You did not select an item. This process has been stopped.”)); “”);

REM;

tbLNum := @Member(tbChoice; tbChoices);

tbIsFirst := cname = 1;

tbIsLast := tbLNum = tbNum;

tbIsOnly := tbNum = 1;

REM;

FIELD cnamedb := @Subset(@Subset(cname; tbLNum); -1);

FIELD cinfodb := @Subset(@Subset(cinfo; tbLNum); -1);

FIELD cunamedb := @Subset(@Subset(cuname; tbLNum); -1);

FIELD cdatedb := @Subset(@Subset(cdate; tbLNum); -1);

REM;

tbRet := @DialogBox(“Contractordetails”; [AutoHorzFit] : [AutoVertFit]);

@If(tbRet = 0; @Return(“”); “”);

@If(“” != cnamedb : cinfodb: Cunamedb : cdatedb; “”; @Return(“”));

REM;

FIELD cname := @If(tbIsOnly; cnamedb; tbIsFirst; cnamedb : @Subset(cname; 1 - tbNum); tbIsLast; @Subset(cname; tbNum - 1) : cnamedb; @Subset(cname; tbLNum - 1) : cnamedb : @Subset(cname; tbLNum - tbNum));

FIELD cinfo := @If(tbIsOnly; cinfodb; tbIsFirst; cinfodb : @Subset(cinfo; 1 - tbNum); tbIsLast; @Subset(cinfo; tbNum - 1) : cinfodb; @Subset(cinfo; tbLNum - 1) : cinfodb : @Subset(cinfo; tbLNum - tbNum));

FIELD cuname := @If(tbIsOnly; cunamedb; tbIsFirst; cunamedb : @Subset(cuname; 1 - tbNum); tbIsLast; @Subset(cuname; tbNum - 1) : cunamedb; @Subset(cuname; tbLNum - 1) : cunamedb : @Subset(cuname; tbLNum - tbNum));

FIELD cdate := @If(tbIsOnly; cdatedb; tbIsFirst; cdatedb : @Subset(cdate; 1 - tbNum); tbIsLast; @Subset(cdate; tbNum - 1) : cdatedb; @Subset(cdate; tbLNum - 1) : cdatedb : @Subset(cdate; tbLNum - tbNum));

REM;

FIELD cnamedb := @DeleteField;

FIELD cinfodb := @DeleteField;

FIELD cunamedb := @DeleteField;

FIELD cdatedb := @DeleteField;

REM;

@Command([ViewRefreshFields])

I am using a different DialogueBox for the edit button, so that the Cuname and Cudate are no longer computed and pick the information from the table, also the Cuname, Cdate abd Cname are hidden so only the Cinfo is editable on the DialougeBox.

This seems to work ok, but I do get this error at time when editing one of the lines:-

ERROR: The second argument to @Subset must not be zero.

I have looked at my code but cant see anything wrong, can you shed some light on this for me. This problem only started after I added the other two fields, so it may be something I have missed out when adding the new fields.

Regards

Douglas Bell

Subject: You missed something…

You had:tbLNum := @Member(tbChoice; tbChoices);

tbIsFirst := cname = 1;

tbIsLast := tbLNum = tbNum;

tbIsOnly := tbNum = 1;

Should be

tbLNum := @Member(tbChoice; tbChoices);

tbIsFirst := tbLNum = 1;

tbIsLast := tbLNum = tbNum;

tbIsOnly := tbNum = 1;

Subject: RE: You should be able to figure out any additional code you need from this…

Doug,

Is this information only used in one place?

Look back at my original response. Create a “Contractor Profile” document that stores this information and include it as an embedded view. That way each contractor has their own document that is much easier to maintain/format than what you are trying to do here, and is easily available other places in the application for lookups, etc.

Subject: What I typically do is Truncate entries, Then place a hotspot around the field that displays the full List.

i.e. Create a field call “DispYourField2” Computed For Display with a formula like this:T1 := YourField2;

Len1 := 30;

TruncatedLong := @Left(T1; Len1);

TooLong := @Trim(@Replace(T1; TruncatedLong; “”));

ReplaceLong := @Left(TooLong; Len1) + “…”;

@Replace(T1; TooLong; ReplaceLong)