jforget1
asked on
Trouble with SaveOptions
Having some trouble with my saving on a doc I have the code below in the SaveOptions field. I also have a validation on the exiting of the username field to make sure the user has not already started a version of this doc before. Now when it runs the script and validates that this would be a duplicate, it closes the form but it saves a copy anyways. How can I tweak these 2 to validate properly but not save the duplicate.
Code in Saveoptions field:
@If(@IsNewDoc ; "1" ; "0")
Exiting code in username field:
Sub Exiting(Source As Field)
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim username As String
Dim ndoc As NotesDocument
Dim cdoc As NotesDocument
Set uidoc = workspace.CurrentDocument
Set db = session.CurrentDatabase
Set ndoc = uidoc.Document
Set view = db.GetView("(completed)")
Call uidoc.Save
username = uidoc.FieldGetText( "username")
key = username
Set cdoc = view.GetDocumentbyKey(key)
If cdoc Is Nothing Or cdoc.NoteID= ndoc.NoteID Then
Exit Sub
Else
Msgbox "You have already started a Self-Assessment, please edit that version."
Set doc = uidoc.Document
doc.SaveOptions = "0"
Call uidoc.close
End If
End Sub
Code in Saveoptions field:
@If(@IsNewDoc ; "1" ; "0")
Exiting code in username field:
Sub Exiting(Source As Field)
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim username As String
Dim ndoc As NotesDocument
Dim cdoc As NotesDocument
Set uidoc = workspace.CurrentDocument
Set db = session.CurrentDatabase
Set ndoc = uidoc.Document
Set view = db.GetView("(completed)")
Call uidoc.Save
username = uidoc.FieldGetText( "username")
key = username
Set cdoc = view.GetDocumentbyKey(key)
If cdoc Is Nothing Or cdoc.NoteID= ndoc.NoteID Then
Exit Sub
Else
Msgbox "You have already started a Self-Assessment, please edit that version."
Set doc = uidoc.Document
doc.SaveOptions = "0"
Call uidoc.close
End If
End Sub
Don't put the code in the exiting event, Try putting the code in query save there you have option of not saving the document by using continue = false and that's the best way to code as the user may avoid the firing of exiting event by not tabbing the field
ASKER
The only problem with that is I also don't want the user to go through the whole form and then find out it is a duplicate. The entry of the form is long and would be bad to find out after all the data entry.
Don;t have any formula on teh saveoptions, but just have the field, and why do u do the uidoc.save , remove that line it should work..
Partha
Partha
SO ideally your code should be :
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim username As String
Dim ndoc As NotesDocument
Dim cdoc As NotesDocument
Set uidoc = workspace.CurrentDocument
Set db = session.CurrentDatabase
Set ndoc = uidoc.Document
Set view = db.GetView("(completed)")
username = uidoc.FieldGetText( "username")
key = username
Set cdoc = view.GetDocumentbyKey(key)
If cdoc Is Nothing Or cdoc.NoteID= ndoc.NoteID Then
Exit Sub
Else
Msgbox "You have already started a Self-Assessment, please edit that version."
Set doc = uidoc.Document
doc.SaveOptions = "0"
Call uidoc.close
End If
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim username As String
Dim ndoc As NotesDocument
Dim cdoc As NotesDocument
Set uidoc = workspace.CurrentDocument
Set db = session.CurrentDatabase
Set ndoc = uidoc.Document
Set view = db.GetView("(completed)")
username = uidoc.FieldGetText( "username")
key = username
Set cdoc = view.GetDocumentbyKey(key)
If cdoc Is Nothing Or cdoc.NoteID= ndoc.NoteID Then
Exit Sub
Else
Msgbox "You have already started a Self-Assessment, please edit that version."
Set doc = uidoc.Document
doc.SaveOptions = "0"
Call uidoc.close
End If
ASKER
Do I make the SaveOptions Editable or Conputed?
ASKER
I get an Object variable not set when I rem the Uidoc.Save line.
what line you get the error, use debugger and tell us the exact line that is causing the error
ASKER
It is happening at this line
Set cdoc = view.GetDocumentbyKey(key)
Set cdoc = view.GetDocumentbyKey(key)
that means that view doesn't exist. check whether the view by that name exists, or is it spelled correctly
partha
partha
ASKER
If i take off the rem on the uidoc.save line I do not get the error.
If you put uidoc.save what happens is, even before u check whether teh document needs to be saved or not, it's already saved. So when you say uidoc.close , the document had been saved 20 lines before and it simply closes the document, I feel the error is somewhere else, what do u mean by take off the rem on uidoc.save , just remove that line
Partha
Partha
ASKER
I took that line out completely and I get the Object variable not set error again. I will keep trying.
Try this:
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim username As String
Dim ndoc As NotesDocument
Dim cdoc As NotesDocument
Set uidoc = workspace.CurrentDocument
Set db = session.CurrentDatabase
Set ndoc = uidoc.Document
Set view = db.GetView("(completed)")
if view is nothing then
msgbox " the view is not found please check whether u have spelled me correct, try removing the bracket and check
end if
username = uidoc.FieldGetText( "username")
key = username
Set cdoc = view.GetDocumentbyKey(key)
If cdoc Is Nothing Or cdoc.NoteID= ndoc.NoteID Then
Exit Sub
Else
Msgbox "You have already started a Self-Assessment, please edit that version."
Set doc = uidoc.Document
doc.SaveOptions = "0"
Call uidoc.close
End If
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim username As String
Dim ndoc As NotesDocument
Dim cdoc As NotesDocument
Set uidoc = workspace.CurrentDocument
Set db = session.CurrentDatabase
Set ndoc = uidoc.Document
Set view = db.GetView("(completed)")
if view is nothing then
msgbox " the view is not found please check whether u have spelled me correct, try removing the bracket and check
end if
username = uidoc.FieldGetText( "username")
key = username
Set cdoc = view.GetDocumentbyKey(key)
If cdoc Is Nothing Or cdoc.NoteID= ndoc.NoteID Then
Exit Sub
Else
Msgbox "You have already started a Self-Assessment, please edit that version."
Set doc = uidoc.Document
doc.SaveOptions = "0"
Call uidoc.close
End If
ASKER
I pasted yours in directly and get the same Object error at the same Set cdoc line as before.
Did you get any message like view not found.
ASKER
No it went right past that. I know the view is there.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I did not write the initial but I believe that is what is doing the comparison if there is a conflict.
I assume that you want to check the whole condition only if it is a new document right, for that you can just use
If uidoc.IsNewDoc Then . I am not sure what's the use of noteid comparison
partha
If uidoc.IsNewDoc Then . I am not sure what's the use of noteid comparison
partha
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I did not write the code, got this from someone else, I just want to do an evaluation if the person has already started a form for themselves without them filling out the entire thing and then it tells them it is a duplicate. I am open to any new code or suggestions, I will try and work in the changes from Sjef.
ASKER
mbonaci
Adding the two lines of code you suggested worked, it did all the evaluations properly. Thanks to all for the help.
Joe
Adding the two lines of code you suggested worked, it did all the evaluations properly. Thanks to all for the help.
Joe
Just give an A next time...
jforget1,
Seriously, why B?
My answer was right on the spot.
https://www.experts-exchange.com/help.jsp#hi73
Marko
Seriously, why B?
My answer was right on the spot.
https://www.experts-exchange.com/help.jsp#hi73
Marko
"My" ??? "Our" !!
ASKER
I am sorry I did not realize that was a real big deal, can I change it, I will. It was my bad, I really do appreciate the help.
sorry Sjef, "Our" of course, I sometimes tend to be a bit egoistic ;)
As I already said, all great tips, you know I didn't mean that ;)
Marko
As I already said, all great tips, you know I didn't mean that ;)
Marko
jforget1, just put a question in Community Support asking to reopen this question. Don't forget the link to this one!
You can also ask them to just change the grade...
ASKER
I have requested this be changed.