Link to home
Start Free TrialLog in
Avatar of David Schmalzer
David SchmalzerFlag for United States of America

asked on

Formula Loop

In the postopen event of a form, I have a dialogbox pop up to fill in a field. Now, what I want is, for that box to keep popping up until the field is filled in just in case someone might just click on the x and close the dialog box window.  How do I do it?
Avatar of HemanthaKumar
HemanthaKumar

Here is a example

     Dim db As NotesDatabase
     Dim s As New NotesSession
     Dim workspace As New NotesUIWorkspace
     Dim view As NotesView
     Dim doc As NotesDocument
     Set db = s.CurrentDatabase
     Set doc = db.CreateDocument
callDialog:
' Call the dialog box with doc as paremeter
Call workspace.DialogBox _
        ("Dialog Box", True, True, False, False, False,  _
     False, "Dialog Box", doc)

if doc.FieldRequired(0) = "" then goto callDialog

~Hemanth
Can't really do it directly in R5.  R6 has @formula looping mechanisms.

What you can do is set a flag field that indicates when the formula has reached completion, put @If(flag_set; @Return(COMPLETE); @PostedCommand([ViewRefreshFields])) at the top, and put a copy of the formula in PostRecalc, if it isn't already occupied.  That will cause the formula to exit immediately if it ever completed, but otherwise, force a recalc before it even starts.  Effectively, the formula keeps looping, because the reccalc does the same thing, forcing itself to run again immediately after it completes.
Avatar of David Schmalzer

ASKER

Heman,
Please clarify, let's say the field name is field1. Where do I plug that in?
That will be in the if condition

if doc.Field1(0) = "" then goto callDialog
You'll need to use the 'source' uidocument, instead of creating a new document.
Put this in the postopen event :

Dim db As NotesDatabase
     Dim s As New NotesSession
     Dim view As NotesView
     dim returnValue as integer
    if source.isNewDoc then
Do While source.document.Field1(0) = "" 
returnValue = workspace.DialogBox _
        ("Dialog Box", True, True, False, False, False,  _
     False, "Dialog Box", doc)
if not returnValue then
' stop it here
' close the document if cancelled
source.document.saveoptions = "0" 'you may need to add a text field, saveoptions, editable, value "1", to the form
call source.close()
end if
end if
Loop


Here, the user can cancel too, and the document will close ...

cheers,

Tom
Variant does not contain an object
Sorry guys, getting problems or errors on both scripts as follows.

Heman's: The loop never stops. Dialog box won't go away, even when filled in.


Bozz : Unexpected Endif Expected Loop.
Are you using correct field name ??? If not it always says that if condition is true and keeps looping .. check the spelling too
Heman repost the correct code with these plugged in so I will know if I did it right.
The name of the field is proj num.  The name of the form with the layout region is projnum.

Thanks.
Dim db As NotesDatabase
     Dim s As New NotesSession
     Dim view As NotesView
     dim returnValue as integer
    if source.isNewDoc then
Do While source.document.Field1(0) = "" 
returnValue = workspace.DialogBox _
        ("Dialog Box", True, True, False, False, False,  _
     False, "Dialog Box", doc)
if not returnValue then
' stop it here
' close the document if cancelled
source.document.saveoptions = "0" 'you may need to add a text field, saveoptions, editable, value "1", to the form
call source.close()
end if

Loop

end if
ASKER CERTIFIED SOLUTION
Avatar of HemanthaKumar
HemanthaKumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Correct, the field name is actually proj_num.

Still getting error though.  Variant does not contain an object.
switch on debugger and see which line is giving that error.
I think it is this one.  if doc.ProjNum(0) = "" then goto callDialog

The dialog box pops up, I enter my value and then I can't get it to disappear.  I have to end task to close notes and then reboot.
Can you post your code here..Also did you replace the field name properly ??
Yep, I think I did. Here is the code:

Dim db As NotesDatabase
      Dim s As New NotesSession
      Dim workspace As New NotesUIWorkspace
      Dim view As NotesView
      Dim doc As NotesDocument
      Set db = s.CurrentDatabase
      Set doc = db.CreateDocument
callDialog:
' Call the dialog box with doc as paremeter
      Call workspace.DialogBox _
      ("projnum", True, True, False, False, False,  _
      False, "Assign Project Number", doc)
      
      If doc.proj_num(0) = "" Then Goto callDialog
Can u send me the sample databas that has this forms and script ??
Uh oh, EE violation.
OK.