• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 740
  • Last Modified:

QuerySave Continue condition not working

Hi,

I'm using Notes R5 and I stimply want to cancel the save operation based on a certain condition. However, I get the messagebox that says I must enter a report number however, the Continue = False statement doesn't prevent the save process. Am I missing something. Here is a snipplet:

Sub Querysave(Source As Notesuidocument, Continue As Variant)
      Dim WS As New NotesUIWorkspace
      Dim Session As New NotesSession
      Set db = session.CurrentDatabase
      Set docA = WS.CurrentDocument
      
      If docA.fieldgettext("ContNum")="" Then
            Messagebox "You must enter a Report Number"
            Continue = False      
            Exit Sub
      End If
               .... More error checking
End Sub
0
Sarniait
Asked:
Sarniait
  • 2
  • 2
2 Solutions
 
Sjef BosmanGroupware ConsultantCommented:
Firstly, this kind of errorchecking/field validation should be handled on the field level.
Secondly, I avoid using NotesUIDocument. In this case that would result in:
    Dim doc As NotesDocument

    Set doc= ws.CurrentDocument.Document
    If doc.ContNum(0)="" Then
    ...

For the rest, it seems correct to me. You copied/pasted the code straight from the database?

One more thing that might help you: in the Options section of your form, add the line
    Option Declare

That line will enforce a declaration for every variabale. Handy when you can't find a typo...
0
 
SarniaitAuthor Commented:
Bosman,

Ok so I might be over complicating what I really need, which is validation. I'm not a notes developer nor do I pretend to be one =), so this might be a stupid/simple question. How do you preform field validation at the "field level"?
0
 
Sjef BosmanGroupware ConsultantCommented:
Not pretending to be one? Is that so? ;)

Every field has a Validation 'event', the result of which has to be either @Failure or @Success.

Standard for a required field:
    @If(@Text(@ThisValue)=""; @Failure("Required field"); @Success)
and the cursor will be placed in the field.
0
 
SarniaitAuthor Commented:
Interesting. I don't see this event in the event list for any field. Could this be a feature in newer versions?
0
 
marilyngCommented:
In addition to sjef's field validation checking at the field level (BTW, I usually don't do this, I use the query save, but depends)
YOu don't need to instantiate uidoc since SOURCE does this automatically.  I haven't had problems with just setting doc without database or session for a quick validation:

Sub Querysave(Source As Notesuidocument, Continue As Variant)      
     Set docA = source.document
     
     If len(docA.getItemValue("ContNum")(0))=0 Then
          Messagebox "You must enter a Report Number"
          Continue = False    
          Exit Sub
     End If
               .... More error checking
End Sub

--------
Or you can do:
Sub Querysave(Source As Notesuidocument, Continue As Variant)      
         
     If len(source.fieldgetText("ContNum"))=0 Then
          Messagebox "You must enter a Report Number"
          Continue = False    
          Exit Sub
     End If
               .... More error checking
End Sub

Provided that the field "ContNum" is visible and editable, else you would have to use the backend doc to get the value.
-------------------------

If you're going to use the field validation and a button that does:  @Command([FileSave]);@Command([FileCloseWindow])

then you have to test for @isvalid first, else the button save will ramble on, in between the validation error messages.

So, the button formula:

@if(!@isValid;@Return("");"");
@if@Command([FileSave]);@Command([FileCloseWindow]);"")

0
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now