Update field in Postopen or Queryopen

Hi!

When I open a document I want to update some fields in it. The new values do I get from a view in the same database except from one value. That value comes from another database.

I can collect all the values and show them in a messagebox when I open the document. But when I do this code:

Call uidoc.FieldSetText(“DebAnslutning”,Str(sumAnslutning))

It says that I must be i editmode. The problem with this is that not all users who looking at the document have edit rights.

I post all my code I have in Postopen:

Sub Postopen(Source As Notesuidocument)

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As notesDocument

Set uidoc = ws.CurrentDocument

Set doc = uidoc.Document



Dim DebAnslutning As Integer

Dim DebNatverk As Integer 

Dim DebProgram As Integer

Dim DebOvrigt As Integer

Dim Debitering As Variant

Dim AntDeb As Integer



DebAnslutning = uidoc.FieldGetText("DebAnslutning")

DebNatverk =uidoc.FieldGetText("DebNatverk")

DebProgram = uidoc.FieldGetText("DebProgram")

DebOvrigt = uidoc.FieldGetText("DebOvrigt")



Debitering = Split(uidoc.FieldGetText("debitering"), ", ",-1)

AntDeb = (Ubound(Debitering) + 1)



Dim db As NotesDatabase

Dim view As NotesView

Dim entry As NotesViewEntry

Dim vc As NotesViewEntryCollection

Dim viewdoc As NotesDocument	

Dim sum As Integer

Dim sumAnslutning As Integer

Dim sumNatverk As Integer	

Dim sumProgram As Integer

Dim sumOvrigt As Integer

sumAnslutning = 0

sumNatverk = 0

sumProgram = 0

sumOvrig = 0

Set db = session.CurrentDatabase

Set view = db.GetView( "Alla poster\Tjänster" )



For x = 0 To AntDeb-1

	Set vc = view.GetAllEntriesByKey(Debitering(x))

	Set entry = vc.GetFirstEntry()

	Do Until entry Is Nothing

		If entry.ColumnValues(1) = "Anslutning" Then

			sumAnslutning = sumAnslutning + entry.ColumnValues(2)

		End If

		If entry.ColumnValues(1) = "Nätverk" Then

			sumNatverk = sumNatverk + entry.ColumnValues(2)

		End If

		If entry.ColumnValues(1) = "Program" Then

			sumProgram = sumProgram + entry.ColumnValues(2)

		End If

		If entry.ColumnValues(1) = "Övrigt" Then

			sumOvrigt = sumOvrigt + entry.ColumnValues(2)

		End If

		Set entry = vc.GetNextEntry(entry)

	Loop

Next	



'Kontrollera PC-kostnad

Dim MaskinDb As New NotesDatabase( "", "Maskiner.nsf" )

Dim MaskinDoc As NotesDocument	

Dim MaskinView As NotesView

key =  uidoc.FieldGetText("Anr")

Set MaskinView = MaskinDb.GetView ("Maskiner" )

Set MaskinDoc = MaskinView.GetDocumentByKey(key)



Dim sumPC As Variant

sumPC = Maskindoc.GetItemValue( "Kostnad" )

'Slut på PC-kostnadskontroll



Messagebox "PC-kost:  " & sumPC(0) & Chr(13) & "Anslutning:  " & sumAnslutning & Chr(13) & "Nätverk:  " & sumNatverk & Chr(13) & "Program:  " & sumProgram & Chr(13) & "Övrigt:  " & sumOvrigt,, "Riktiga värden"

Call uidoc.FieldSetText("DebAnslutning",Str(sumAnslutning))

Call uidoc.FieldSetText("DebNatverk",Str(sumNatverk))

Call uidoc.FieldSetText("DebProgram",Str(sumProgram))

Call uidoc.FieldSetText("DebOvrigt",Str(sumOvrigt))

End Sub

Thanks for your help!

best regards

Henrik

Subject: Update field in Postopen or Queryopen

Does anyone have any idea?

best regards

Henrik

Subject: RE: Update field in Postopen or Queryopen

If the user does not have the ability to edit the doc then they will not be able to change the value of the field at all. The form events run under the rights of the user opening the doc so even if you attempt to set the field value on the backend whithout going into edit mode it still won’t work.

Subject: Update field in Postopen or Queryopen

In order for people to be able to update fields in the document then they need to be able to edit the document. You can stop them being able to amend the other parts of the document by methods like using controlled access sections or using roles and computed for display fields to hide the editable fields.