LS Code Problem - Help needed and appreciated

Hi,

The code below should be assigning a bid number but it’s assigning the field as Draft, does anyone happen to know why?

There are no other entries in this db, it’s the first one.

There a bit more code below what I’ve put to do with something else. I’ve missed this off as the code above is the problem.

Thanks,

Hayley.

'--------------------------------------------------------------------------------------

'-- Generate Bid number - based on a combination of

'-- Yr + Centre + Bid Sequence number

'--------------------------------------------------------------------------------------

Dim session As New NotesSession     

Dim db As NotesDatabase        

Dim doc As NotesDocument

Dim doc1 As NotesDocument

Dim curdoc As NotesDocument     

Dim BidNumDoc As NotesDocument

Dim ClientAbbrView, BidNumView As NotesView    

Dim column As NotesViewColumn

Dim DivAbbrev As Variant                             ' Division Abbreviation

Dim BidYear As Variant                                

Dim SeqNum, SeqNum1 As Variant               

Dim SeqNumInt As Integer   

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim vc As NotesViewEntryCollection

Dim entry As NotesViewEntry



Set uidoc = workspace.CurrentDocument

Set curdoc = uidoc.Document

Set db = session.CurrentDatabase    

Set BidNumView = db.GetView("BidNum")

Set doc=uidoc.document

SeqNum1 = ""



uidoc.EditMode = True



clientkey = curdoc.Centre(0)

YrBidNum = Evaluate("@Year(DueDate)", curdoc)

Set vc = BidNumView.GetAllEntriesByKey(YrBidNum(0))

If Not(vc.Count = 0) Then

	Set entry = vc.GetLastEntry()

	Set doc = entry.Document

	

	If Not(doc Is Nothing) Then

		SeqNum1 = Right$(doc.FileNumber(0), 3)           'ColumnValues(0)                   

	End If

End If



If SeqNum1 = "" Then       

	SeqNum = "0"

Else 

	SeqNum = SeqNum1  

End If



If SeqNum = "" Then

	SeqNum = "-1"

End If



SeqNumInt = Clng(SeqNum)

SeqNum = Right$("00" & Cstr(SeqNumInt + 1),3)

BidYear = Right$(YrBidNum(0),1)

BidNum = BidYear + SeqNum

Call uidoc.FieldSetText( "FileNumber", Cstr(BidNum))

Subject: LS Code Problem - Help needed and appreciated.

Here it is:

Sub Click(Source As Button)

'--------------------------------------------------------------------------------------

'-- Generate Bid number - based on a combination of

'-- Yr + Centre + Bid Sequence number

'--------------------------------------------------------------------------------------

Dim session As New NotesSession     

Dim db As NotesDatabase        

Dim doc As NotesDocument

Dim doc1 As NotesDocument

Dim curdoc As NotesDocument     

Dim BidNumDoc As NotesDocument

Dim ClientAbbrView, BidNumView As NotesView    

Dim column As NotesViewColumn

Dim DivAbbrev As Variant                             ' Division Abbreviation

Dim BidYear As Variant                                

Dim SeqNum, SeqNum1 As Variant               

Dim SeqNumInt As Integer   

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim vc As NotesViewEntryCollection

Dim entry As NotesViewEntry



Set uidoc = workspace.CurrentDocument

Set curdoc = uidoc.Document

Set db = session.CurrentDatabase    

Set BidNumView = db.GetView("BidNum")

Set doc=uidoc.document

SeqNum1 = ""

'-- Error checks

If Not(curdoc.FileNumber(0) = "") And Not(curdoc.FileNumber(0) = "Draft") Then

	Msgbox("Bid already has a number assigned to it")

	Exit Sub

End If

If (uidoc.FieldGetText("Client") = "") Then

	Msgbox("You must enter a value for Client")

	Call uidoc.GotoField( "Client" )

	continue = False

	Exit Sub          

End If

If (uidoc.FieldGetText("Centre") = "") Then

	Msgbox("You must enter a value for Centre")

	Call uidoc.GotoField( "Centre" )          

	continue = False

	Exit Sub

End If

If (uidoc.FieldGetText("Country") = "") Then

	Msgbox("You must enter a value for Country")

	Call uidoc.GotoField( "Country" )          

	continue = False

	Exit Sub

End If

If (uidoc.FieldGetText("Region") = "") Then

	Msgbox("You must enter a value for Sub-Region via the Country field")

	Call uidoc.GotoField( "Country" )          

	continue = False

	Exit Sub

End If



If ( uidoc.FieldGetText( "DueDate" ) = "" ) Then

	Msgbox("You must enter a Due Date for the Bid")

	Call uidoc.GotoField( "DueDate" )          

	continue = False

	Exit Sub          

End If     

'-- END Error checks

uidoc.EditMode = True



clientkey = curdoc.Centre(0)

YrBidNum = Evaluate("@Year(DueDate)", curdoc)

Set vc = BidNumView.GetAllEntriesByKey(YrBidNum(0))

If Not(vc.Count = 0) Then

	Set entry = vc.GetLastEntry()

	Set doc = entry.Document

	

	If Not(doc Is Nothing) Then

		SeqNum1 = Right$(doc.FileNumber(0), 3)           'ColumnValues(0)                   

	End If

End If



If SeqNum1 = "" Then       

	SeqNum = "0"

Else 

	SeqNum = SeqNum1  

End If



If SeqNum = "" Then

	SeqNum = "-1"

End If



SeqNumInt = Clng(SeqNum)

SeqNum = Right$("00" & Cstr(SeqNumInt + 1),3)

BidYear = Right$(YrBidNum(0),1)

BidNum = BidYear + SeqNum

Call uidoc.FieldSetText( "FileNumber", Cstr(BidNum))

%REM

Author:			Hayley Kenward

Date: 			11 April 2005

Description:	Moved the approval scripts section from QuerySave to this button.

Sections:		1)Sends the QC Approval email to the relevant people

Modified Date:	

%END REM

If ( Trim(curdoc.EmailStatus(0)) <> "" ) Then

	Dim user As String

	Dim Num As Double

	Dim aString As String

	

	doc.QCToggle="Yes"

	

	user=session.UserName

	BidNumber=uidoc.FieldGetText("FileNumber")

	

	uidoc.Refresh

' Sends the QC Approval email to the relevant people

	

	Dim newdoc As NotesDocument

	Set newdoc=New NotesDocument(db)

	Dim rtitem As NotesRichTextItem

	Set rtitem=New NotesRichTextItem(newdoc,"Body")

	

	newdoc.Form="Memo"

	newdoc.SendTo=doc.QCApprovalSendTo

	newdoc.CopyTo=doc.user

	newdoc.Subject="QC Approval required for Bid Number " & BidNumber

	uidoc.Refresh

	

	Call doc.Save(True,False)

	

	Call rtitem.AddNewLine(2)

	Call rtitem.AppendText("The Bid number referenced above is ready for QC")

	Call rtitem.AddNewLine(2)

	Call rtitem.AppendText("This will register the date and name of the approver.")

	Call rtitem.AddNewLine(4)

	Call rtitem.AppendText("Bid No				")

	Call rtitem.AppendText(doc.FileNumber(0))

	Call rtitem.AddNewLine(1)

	Call rtitem.AppendText("Status				")

	Call rtitem.AppendText(doc.Status(0))

	Call rtitem.AddNewLine(1)

	Call rtitem.AppendText("Client				")

	Call rtitem.AppendText(doc.Client(0))

	Call rtitem.AddNewLine(1)

	Call rtitem.AppendText("Country				")

	Call rtitem.AppendText(doc.Country(0))

	Call rtitem.AddNewLine(1)

	Call rtitem.AppendText("Survey Size			")

	Call rtitem.AppendText(doc.Volume(0))

	Call rtitem.AddNewLine(1)

	Call rtitem.AppendText("Survey Type			")

	Call rtitem.AppendText(doc.Dimension(0))

	Call rtitem.AddNewLine(1)

	Call rtitem.AppendText("Bid Total			")

	Call rtitem.AppendText(doc.BidTotal(0))

	Call rtitem.AddNewLine(1)

	Call rtitem.AppendText("Contact				")

	Call rtitem.AppendText(doc.VeritasContact(0))

	Call rtitem.AddNewLine(1)

	Call rtitem.AppendText("Chance of winning		")

	Call rtitem.AppendText(doc.Significance(0))

	Call rtitem.AddNewLine(1)

	Call rtitem.AppendText("Comments			")

	Call rtitem.AppendText(doc.Comments(0))

	Call rtitem.AddNewLine(2)

	Call rtitem.AppendText("Please follow link to view bid ->>  ")

	Call rtitem.AppendDocLink(doc,db.Title)

	Call newdoc.Send(False)

End If



Call uidoc.Save

Call uidoc.Close		



Exit Sub

ErrorHandler:

Messagebox "Bid Number Error - Could not generate a Bid Number, Please contact your database administrator"

Continue=False

Exit Sub



Call uidoc.Save

Call uidoc.Close

Exit Sub

End Sub

Subject: LS Code Problem - Help needed and appreciated.

Sorry, in the QuerySave event, I have this code:

If ( source.FieldGetText( "FileNumber" ) = "" ) Then

	Call source.FieldSetText( "FileNumber", "Draft" )

End If

So it means the Assign Bid Number button, which the code is in my first post is not working correctly, because it should be assigning a bid number and not Draft.

Subject: RE: LS Code Problem - Help needed and appreciated.

hmm

Can you post the rest of the button code? I can’t see anything in that off the top of my head.

also, does the field value change after the button has been pressed? Are there any validation/translation formulae on the FileNumber field?

Thanks

Kieran

Subject: LS Code Problem - Help needed and appreciated.

Can you explain what you mean by “Its assigning the field as Draft”?

THanks

Kieran