I have created a scheduled agent which produces this error msg. "Cannot open databases on machines other than the server running your program (Server!!Dir\Filename.nsf) Databases are on the same server where the code resides. Please help. See The code below:
Sub Initialize
Dim ses As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim profdoc As NotesDocument
Dim ProductDB As NotesDatabase
Dim ProductDBServer As String
Dim ProductDBPath As String
Dim ProductView As NotesView
Dim ProcessView As NotesView
Dim ProductLibAgentDate As New NotesDateTime ("")
Dim vc As NotesViewEntryCollection
Dim entryOne As NotesViewEntry
Dim entryTwo As NotesViewEntry
Dim entryLast As NotesViewEntry
Dim RefOldSAPID As Variant
Dim RefOldDesc As Variant
Dim RefItemSAPID As Variant
Dim RefItemDesc As Variant
Dim RefOldSAPID2 As Variant
Dim RefOldDesc2 As Variant
Dim RefItemSAPID2 As Variant
Dim RefItemDesc2 As Variant
Dim RefOldProd1 As Variant
Dim RefProd1 As Variant
Dim RefOldProd2 As Variant
Dim RefProd2 As Variant
Dim RefOldProd3 As Variant
Dim RefProd3 As Variant
Dim RefOldProd4 As Variant
Dim RefProd4 As Variant
Dim RefOldProd5 As Variant
Dim RefProd5 As Variant
Dim RefOldProd6 As Variant
Dim RefProd6 As Variant
Dim refDoc As NotesDocument
Dim key1 As Variant
Dim key2 As Variant
Dim LibUpdate As Variant
Dim Item1, Item2, Item3 As NotesItem
Dim Item4, Item5, Item6 As NotesItem
Dim Item7, Item8, Item9 As NotesItem
Dim counter, processcounter As Integer
Dim success As Variant
Dim processcounterP As Integer
Dim agentrun As String
Dim i As Variant
Set gmwvLog=New MeadWestVacoLog("Update Fields from Product Library")
Call gmwvLog.write(gmwvLog.LE_NORMAL, "Begin running Update Fields from Product Library at: " & Now())
'--------------------------DB Lookup Routine ------------------------------------------------
Set profdoc = ses.currentDatabase.GetProfileDocument("ProfileDoc")
ProductDBServer = profdoc.ProductServer(0)
ProductDBPath = profdoc.ProductPath(0)
Set ProductDb = New NotesDatabase(ProductDBServer, ProductDBPath)
Set ProductView =ProductDb.GetView("ERPLookupItemLegacy")
agentrun = profdoc.RunAgentFlag(0)
If agentrun = "No" Then
Goto AGENTRUNNO
End If
'------------------------------------------------------------------------------------------------------
Call gmwvLog.write(gmwvLog.LE_NORMAL, ProductDb.Title & " is available at location: " & " " & ProductDb.Server & _
" - " & ProductDb.Filename)
Set db = ses.CurrentDatabase
Set Processview = db.GetView("vSPECProcess")
Call Processview.Refresh
Set vc = Processview.AllEntries
Set entryOne = vc.GetFirstEntry()
Set entryLast = vc.GetLastEntry()
Set doc = entryOne.Document
counter = 0
processcounter = 0
processcounterP = 0
Call ProductLibAgentDate.setnow ' Set datetime value to now.
LibUpdate = ProductLibAgentDate.DateOnly
Call gmwvLog.write(gmwvLog.LE_NORMAL, "Processing all documents in Process View: " & vc.Count & " Documents to process." )
Print "Update Field from Product Library process has started "
While Not( doc Is Nothing)
key1 = doc.GetItemValue("Item_no")
Key2 = Trim(Key1(0))
Set refDoc = ProductView.GetDocumentByKey( Key2 , True )
'------------- Check for matching document in Product Library Database -------------
If refDoc Is Nothing Then
Goto NextDoc
End If
'------------- Store fields before checking if document is updated already ------------
RefOldSAPID = Trim(doc.GetItemValue("SAPItem_no")(0))
RefItemSAPID = Trim(refDoc.GetItemValue("Item_no")(0))
RefOldDesc = Trim(doc.GetItemValue("Desc")(0))
RefItemDesc = Trim(refDoc.GetItemValue("Desc")(0))
RefOldProd1 = Trim(doc.GetItemValue("PH_1")(0))
RefProd1 = Trim(refDoc.GetItemValue("Prod_Hier_01")(0))
RefOldProd2 = Trim(doc.GetItemValue("PH_2")(0))
RefProd2 = Trim(refDoc.GetItemValue("Prod_Hier_02")(0))
RefOldProd3 = Trim(doc.GetItemValue("PH_3")(0))
RefProd3 = Trim(refDoc.GetItemValue("Prod_Hier_03")(0))
RefOldProd4 = Trim(doc.GetItemValue("PH_4")(0))
RefProd4 = Trim(refDoc.GetItemValue("Prod_Hier_04")(0))
RefOldProd5 = Trim(doc.GetItemValue("PH_5")(0))
RefProd5 = Trim(refDoc.GetItemValue("Prod_Hier_05")(0))
RefOldProd6 = Trim(doc.GetItemValue("PH_6")(0))
RefProd6 = Trim(refDoc.GetItemValue("Prod_Hier_06")(0))
'03/2005 - need to include Product Hiearchy fields to ensure NA Prod Code lookup the correct Product Level
'------------- If document has been updated, skip to next entry in the view -------------
If RefOldSAPID = RefItemSAPID And RefOldDesc = RefItemDesc And RefOldProd1= RefProd1 And RefOldProd2= RefProd2 And _
RefOldProd3= RefProd3 And RefOldProd4= RefProd4 And RefOldProd5= RefProd5 And RefOldProd6= RefProd6 Then
Goto NextDoc
End If
'--------- Update & Save document with info from Product Library Database ----------
Set Item1 = doc.ReplaceItemValue( "SAPItem_No", RefItemSAPID)
Set Item2 = doc.ReplaceItemValue( "Desc", RefItemDesc )
Set Item3 = doc.ReplaceItemValue( "PH_1", RefProd1)
Set Item4 = doc.ReplaceItemValue( "PH_2", RefProd2)
Set Item5 = doc.ReplaceItemValue( "PH_3", RefProd3)
Set Item6 = doc.ReplaceItemValue( "PH_4", RefProd4)
Set Item7 = doc.ReplaceItemValue( "PH_5", RefProd5)
Set Item8 = doc.ReplaceItemValue( "PH_6", RefProd6)
Set Item9 = doc.ReplaceItemValue("ProdLibUpdate", LibUpdate )
success = doc.ComputeWithForm( False, False )
Call doc.Save( True, True )
Call gmwvLog.write(gmwvLog.LE_HIGHLIGHT, "Updated document: Legacy Item " & key2 & " and SAP Item " & RefItemSAPID & " with desc: " & RefItemDesc & " successfully." )
counter = counter + 1
NextDoc:
Set entryTwo = vc.GetNextEntry(entryOne)
If entryTwo.UniversalID = entryLast.UniversalID Then
Goto DONE
End If
Set entryOne = EntryTwo
Set doc = entryOne.Document
processcounter = processcounter + 1
processcounterP = processcounterP + 1
'Print "Processing document number " & processcounter
If processcounterP = 250 Then
Print "Processing document number " & processcounter & " out of " vc.Count
processcounterP = 0
End If
'If counter = 5 Then
' Goto DONE
'End If
Wend
DONE:
Print "Update Field from Product Library processed " & counter & " out of " & processcounter & " successfully!"
Call gmwvLog.write(gmwvLog.LE_HIGHLIGHT, "Update Field from Product Library processed " & counter & _
" out of " & processcounter & " successfully!" )
Call gmwvLog.close()
Exit Sub
AGENTRUNNO:
Print "Update Field from Product Library agent not running, FLAG set to NO!"
Call gmwvLog.write(gmwvLog.LE_HIGHLIGHT, "Update Field from Product Library agent not running. FLAG set to NO!" )
Call gmwvLog.close()
Exit Sub
logerror:
Call logLSError("Initialize")
Exit Sub
End Sub