I have the following code in place. I would like to search a view for Unit Number if no match, then check another view for Serial Number - If not found in either view send email. My problem is after it updates/create the first doc - rdoc has no values and it treats the second search as it is not found in either view and send email. Any help would be appreciated…thanks.
Function GetUnitInfo(varUnitNum) As Variant
Dim strFileName
GetUnitInfo = False
strFileName = Left$(ldb.FilePath, Instr(ldb.FilePath, ldb.FileName) - 1) + "GlobalUnits.nsf"
Set rdb = New NotesDatabase(ldb.Server, strFileName)
If rview Is Nothing Then Set rview = rdb.getview("HIDUnitByID")
Set rdoc = rview.getdocumentbykey(formatUnitNumber(Cstr(varUnitNum)))
If rdoc Is Nothing Then
GetUnitInfo = False
Else
GetUnitInfo = True
End If
If rdoc Is Nothing Then
Set rview = rdb.getview("HIDUnitBySerial")
Set rdoc = rview.getdocumentbykey( "UN_SerialNo" )
Set rdoc = rview.getdocumentbykey(formatUnitNumber(Cstr(varUnitNum)))
If rdoc Is Nothing Then
GetUnitInfo = False
Messagebox("Send Email")
Else
GetUnitInfo = True
End If
End If
Subject: updating doc based on a key in 2 different views
Why are u using same variable names for rdoc. Use different variables(rdoc for first and newrdoc for second) and before sending the mail check “if rdoc and newrdoc is nothing”
Subject: RE: updating doc based on a key in 2 different views
I should have mentioned I am new to Notes and script. I have revised the code below and it is finding the correct view when I used different variables. But, now I need to somehow exit the sub if the key is not found in either view to create a new doc. The update portion is working fine when the key is found in either view. Thanks in advance.
Function GetUnitInfo(varUnitNum) As Variant
Dim strFileName
GetUnitInfo = False
strFileName = Left$(ldb.FilePath, Instr(ldb.FilePath, ldb.FileName) - 1) + "GlobalUnits.nsf"
Set rdb = New NotesDatabase(ldb.Server, strFileName)
If rview Is Nothing Then Set rview = rdb.getview("HIDUnitByID")
Set rdoc = rview.getdocumentbykey(formatUnitNumber(Cstr(varUnitNum)))
If Not rdoc Is Nothing Then
GetUnitInfo = True
End If
If rdoc Is Nothing Then
If rsview Is Nothing Then Set rsview = rdb.getview("HIDUnitBySerial")
Set rdoc = rsview.getdocumentbykey(formatUnitNumber(Cstr(varUnitNum)))
If Not rdoc Is Nothing Then
GetUnitInfo = True
Else
GetUnitInfo = False
If rdoc Is Nothing Then
If rsdoc Is Nothing Then
GetUnitInfo = False
Messagebox("Send Email")
End If
End If
End If
End If