Search code examples
lotus-noteslotusscript

Error type mismatch with replaceitemvalue


I have a problem with a subrutine, i want to replace a value of a field in other form in the same database, my code runs ok if i put it into a buttom, but i wish to do a sub because i want to use it more times.

So, i have this code:

Public Sub actualizarContador (contadorId As String, contadorTmp As Integer, contadorActual As Integer,contadorNuevo As Integer)
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim uidoc As NotesUIDocument
Dim odoc As NotesDocument
Dim estado As String

Set uidoc = ws.Currentdocument
estado = uidoc.Fieldgettext("Estado")

If estado = "Borrador" Then
    Set odoc = db.GetDocumentByUNID(uidoc.FieldGetText(contadorId))
    contadorTmp = Cint(contadorActual) + 1
    Call odoc.ReplaceItemValue(contadorNuevo, contadorTmp)
    Call odoc.Save(True, True)
End If
end sub

Then into a buttom I use this line:

Call actualizarContador (doc.TempoIDContador(0), doc.TempoContadorTmp(0), doc.TempoContadorActual(0), "ContadorUnicoTempo")

I have an error with ContadorUnictoTempo because a must put into this object a name of a field, i think, but this field has numeric format.

Any suggest?

Thanks all.

Edit:

I have fixed the problem, thanks Knut. There were two problems, the first was the field 'ContadorTmp', it hadn't value, now It has 0 as predetermined. This were the first error of type mismatch.

The second error was the class uidoc, it didn´t find the id field. I just finished the code and it runs ok.

Public Sub actualizarContador (contadorId As String, contadorTmp As Integer, contadorActual As Integer, contadorNuevo As String)
Dim ws As New NotesUIWorkspace
Dim ns As New NotesSession
Dim db As NotesDatabase
Dim uidoc As NotesUIDocument
Dim odoc As NotesDocument
Dim estado As String
Dim id As String

set db = ns.Currentdatabase
Set uidoc = ws.Currentdocument
estado = uidoc.Fieldgettext("Estado")
id = contadorId

If estado = "Borrador" Then

    Set odoc = db.GetDocumentByUNID(id)
    contadorTmp = CInt(contadorActual) + 1
    Call odoc.ReplaceItemValue(contadorNuevo, contadorTmp)
    Call odoc.Save(True, True)

End If
End Sub

Solution

  • Define contadorNuevo parameter As String and then it will work.

    Public Sub actualizarContador (contadorId As String, contadorTmp As Integer, 
                                   contadorActual As Integer,contadorNuevo As String)
    

    You should test if odoc got found with

    Set odoc = db.GetDocumentByUNID(uidoc.FieldGetText(contadorId))
    If odoc Is Nothing Then Error 1000, "Couldn't find document"
    ...