Type Mismatch error in lotusscript

I made code to generate a sequential number by looking at a view which has the created date, year, and number, and then incrementing the greatest number by one. . . the code is as follows:

Sub Initialize

Dim workspace As New notesuiworkspace

Dim session As New notessession

Dim db As notesdatabase

Dim uidoc As notesuidocument

Dim lookupdoc As notesdocument

Dim doc As notesdocument

Dim view As notesview

Set db = session.currentdatabase

Set uidoc = workspace.currentdocument

Set doc = uidoc.document



xyear = Format(Date , "yyyy")

key = xyear

Set view = db.getview("DocNo")

Set lookupdoc = view.getdocumentbykey(key)

If lookupdoc Is Nothing Then

	x = 1

	doc.number = 1

Else

	y = lookupdoc.number(0)

	x = y + 1

	doc.number = y + 1

End If

If x <= 9 Then

	DocNo = xyear & "-" & "000" & x

Elseif x > 9 And x <= 99 Then

	DocNo = xyear & "-" & "00" & x

Elseif x > 99 And x <= 999 Then

	DocNo = xyear & "-" & "0" & x

Else

	DocNo = xyear & "-" & x

End If

doc.DocNo = DocNo

Call uidoc.Refresh	

End Sub

This is the code which I use to generate a sequential number on the “onload” event. It works with its own view which has the year, creation date, and the sequential number of each document created. It looks for the last document, and then increments this number by one. Because of access control issues, I am forced to generate a corresponding hidden document which you helped me with, which will hold these document numbers in an access control free environment. Now, what I am trying to do, is use this agent to look in a view which im calling “DocNoHolder” which stores the corresponding hidden documents of the form “DocNoHolder”, look for that last document, and then output the next sequential number generated on the open document. Can someone show me what i need to change to accomplish this? Thanks

Subject: Type Mismatch error in lotusscript

which line are you getting the error

Replace the big if with this format function

Format (x, “0000”)

Subject: RE: Type Mismatch error in lotusscript

That code works completely fine. I just want it to look @ a different view, and document.

Subject: RE: Type Mismatch error in lotusscript

Why does your subject say “Type Mismatch” then?

Subject: Type Mismatch error in lotusscript

Hi Mark.

I’d like to get you on the right programming track here, so can I start off by asking why you are doing this in a Notes Agent? This seems like it would be better off as a Lotus Script library function with a Document paramater. One that perhaps is called during the PostOpen event or something.

Anyhow, even if you don’t do that, at least make certain you have the line:

Option Explicit

or

Option Declare

in your Options section. This will help you avoid many common mistakes, by catching quite a few Type Mismatches during Compile time, as opposed to Runtime (i.e. when you go to save the code, not when you go to run the code.) Not only this, but it usually gives you a better idea of where the error is occuring.

This of course requires you to specifically declare all of your variables, but you absolutely should!

If you’re still having a problem and haven’t been able to figure out what it is, post the Line # that the error is occuring at.

Sorry for not just giving you an answer, but I’m sure you’d rather learn the tools for figuring out the answer yourself, as opposed to having to wait for us all the time. :slight_smile:

  • Steve