Error 538 in Method Movenext

Hi All,

Getting this funky error in method movenext.  This script runs through SOs and deletes the ones in a particular range for a particular customer.  This is the snippet in question.  Any idea what I might have goofed?  it seems to work sometimes, and then not others.

Do While not(cBool(oSO.nEof))
sOrderNo = ""
sCustNo = ""

retval = oSO.nGetValue("SalesOrderNo$", sOrderNo)

retval = oSO.nGetValue("CustomerNo$", sCustNo)

if ucase(sCustNo) = ucase(sCustToDelete) and sOrderNo >= sStartingOrder and sOrderNo <= sEndingOrder then 'delete order if we have a match

retval = oSO.nDelete()

end if

retval = oSO.nMoveNext() '**********ERROR IS HERE*************

Loop

  • 0

    Full script below:

    '******************************************************************************************
    'Deletes Sales Orders in specified range of order numbers and for a selected customer only
    '******************************************************************************************
    Option Explicit

    Dim sUsername, sPassword, sCompany
    'user and pass to use when running script
    sUsername = "vbscript"
    sPassword = "blah"
    sCompany = "TST"

    Dim sRunDate
    'set run date to YYYMMDD format for Sage 100
    sRunDate = Year(now()) & Right(100 + Month(now()), 2) & Right(100 + Day(now()), 2)

    Dim Response, strTempDir, strLogFile

    strTempDir = "c:\temp"
    strLogFile = strTempDir & "\DeleteSalesOrdersLog_" & sRunDate & ".csv"

    dim sStartingOrder, sEndingOrder, sCustToDelete
    sStartingOrder = InputBox("Enter starting Sales Order Number:")

    sEndingOrder = InputBox("Enter ending Sales Order Number:")

    sCustToDelete = InputBox("Enter customer number:")

    'check for valid entries in customer number and orders
    if trim(sStartingOrder) = "" or trim(sEndingOrder) = "" or trim(sCustToDelete) = "" then
    MsgBox("One of the previously entered values was blank. Quitting.")
    wscript.quit
    end if

    'check for valid entries in customer number and orders
    if len(trim(sStartingOrder)) > 7 or len(trim(sEndingOrder)) > 7 then
    MsgBox("One of the previously entered order numbers is greater than 7 characters. Quitting.")
    wscript.quit
    end if

    if not(isnumeric(sStartingOrder)) then
    sStartingOrder = ucase(sStartingOrder)
    end if

    if not(isnumeric(sEndingOrder)) then
    sEndingOrder = ucase(sEndingOrder)
    end if

    if not(isnumeric(sCustToDelete)) then
    sCustToDelete = ucase(sCustToDelete)
    end if


    response = msgbox("Ensure you have a backup of company code " & sCompany & " prior to proceeding." & vbcrlf & vbcrlf & "Orders " & sStartingOrder & " through " & sEndingOrder & " for customer number " & sCustToDelete & " will be deleted." & vbcrlf & "Log will be output to the " & strLogFile & " directory." & vbcrlf & vbcrlf & "Would you like to proceed?", vbyesNo)
    if response <> vbYes Then
    WScript.quit
    end if

    response = msgbox("Are you sure you want to proceed with deletion of order numbers " & sStartingOrder & " through " & sEndingOrder & " for customer number " & sCustToDelete & " in company code " & sCompany & "?" & vbcrlf & vbcrlf &"Log will be output to the " & strLogFile & " directory.", vbyesNo)
    if response <> vbYes Then
    WScript.quit
    end if


    dim oReg, PathHome, PathRoot, oScript, oSS, retVal, oSO, oWriteObj, oWriteCSVObj, recordcount
    dim sCustNo, sOrderNo

    'prepare to write errors to log file
    Set oWriteObj = CreateObject("Scripting.FileSystemObject")
    Set oWriteCSVObj = CreateObject("Scripting.FileSystemObject")

    If NOT (oWriteCSVObj.FolderExists(strTempDir)) Then
    ' Create folder
    oWriteCSVObj.CreateFolder(strTempDir)
    End If


    'Get the ODBC path for the last accessed installation of MAS 90/200
    Const HKEY_CURRENT_USER = &H80000001
    Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
    oReg.GetExpandedStringValue HKEY_CURRENT_USER,"Software\ODBC\ODBC.INI\SOTAMAS90","Directory",PathRoot
    'oReg.GetExpandedStringValue HKEY_CURRENT_USER,"Software\ODBC\ODBC.INI\SOTAMAS90","Directory",PathRoot
    PathHome = PathRoot & "\Home"
    Set oReg = Nothing

    '------------------------------------------------------
    '--- Connect to CI Item Business Object --------------
    '------------------------------------------------------

    'Create ProvideX COM Object for destination company and source company
    Set oScript = CreateObject ("ProvideX.Script")

    'The Init method must be the first method called, and requires the path to the MAS90 home directory
    oScript.Init(PathHome)

    'NewObject method creates a new MAS 90 Session object and returns the objects reference in oSS
    Set oSS = oScript.NewObject("SY_Session")

    'The Logon method returns 1 if MAS90 Security is not enabled or if
    'MAS90 has been configured to use Windows Security
    retVAL = oss.nlogon()

    'If the Logon method fails then you must use the SetUser method to be allowed access
    If retVAL = 0 Then
    'User = Trim(InputBox("Enter User Name")) 'Pompts for username
    'Password = Trim(InputBox("Enter Password")) 'Prompts for password
    retval = oSS.nSetUser(sUsername,sPassword)
    End If

    'If SetUser fails, display LastErrorMsg for reason and quit
    If retVAL = 0 Then
    MsgBox("User Logon failed. Quitting." & oSS.sLastErrorMsg & " " & oSS.sLastErrorMsg)
    cleanUp(oss)
    WScript.quit
    End If

    'Company must be configured to Allow External Access

    retval = oSS.nSetCompany(sCompany)
    'If SetCompany fails, display LastErrorMsg for reason and quit
    If retVAL = 0 Then
    MsgBox("Set Destination Company failed. Quitting." & oSS.sLastErrorMsg)
    cleanup(oss)
    WScript.quit
    End If

    retval = oSS.nSetModule("S/O") 'check retVAL in case module is not activated, etc.
    'If SetModule fails, display LastErrorMsg for reason and quit
    If retVAL = 0 Then
    MsgBox("Error setting the module S/O. Quitting. " & oSS.sLastErrorMsg)
    cleanup(oss)
    wscript.quit
    End If

    ' The SetProgram method is used to get a security object for the Business Object
    retVal = oSS.nSetProgram(oSS.nLookupTask("SO_SalesOrder_Ui"))
    ErrorLog retVal, "Error accessing Item Business Object.", oSS.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
    if retVal = 0 then
    Cleanup(oSS)
    end if
    Set oSO = oScript.NewObject("SO_SalesOrder_bus", oSS)

    ' Terminate UI to avoid screen prompts
    ' oSS.nTerminateUI()

    recordcount = 0

    'loop through all Sales Orders and determine whether it should be deleted
    retVAL = oSO.nMoveFirst()

    Do While not(cBool(oSO.nEof))
    sOrderNo = ""
    sCustNo = ""

    retval = oSO.nGetValue("SalesOrderNo$", sOrderNo)
    ErrorLog retVal, "Error getting order number",oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir

    retval = oSO.nGetValue("CustomerNo$", sCustNo)
    ErrorLog retVal, "Error getting customer number",oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
    'msgbox "Cust No: " & sCustNo & vbcrlf & "Order No: " & sOrderNo
    if ucase(sCustNo) = ucase(sCustToDelete) and sOrderNo >= sStartingOrder and sOrderNo <= sEndingOrder then 'delete order if we have a match

    retval = oSO.nDelete()
    ErrorLog retVal, "Error deleting order number: " & sOrderNo,oSO.sLastErrorMsg, sRunDate, oWriteObj, strLogFile, strTempDir
    ErrorLog 0, "Deleted order number: " & sOrderNo,"", sRunDate, oWriteObj, strLogFile, strTempDir

    if retval <> 0 then
    ErrorLog 0, "Successfully deleted order number " & sOrderNo,"", sRunDate, oWriteObj, strLogFile, strTempDir
    end if
    recordcount = recordcount + 1
    end if

    retval = oSO.nMoveNext()

    Loop

    wscript.echo "Done. Log can be found here: " & vbcrlf & strLogFile
    ErrorLog 0, "Finished.", "", sRunDate, oWriteObj, strLogFile, strTempDir

    cleanup(oSS)

    'oWriteObj.close
    'owriteobj = Nothing
    'oWriteCSVObj.close
    'oWriteCSVObj = Nothing

    '****************************************************************
    'Subroutine to clean up business objects ************************
    '****************************************************************

    Sub cleanUp(Oss)
    'clean up and close business objects
    oSS.nCleanup()
    oSS.DropObject()
    Set oSS = Nothing
    End Sub

    '****************************************************************
    'Subroutine to perform error checking and log error message **
    '****************************************************************
    Sub ErrorLog(RetValue, sErrorMessage, sBOIerror, DateStamp, oWriteObj, strLogFile, strTempDir)

    'Check for and dispaly error messages
    if RetValue = 0 then

    Dim strLine, oWriteLog

    strLine = ""
    DateStamp = Now

    'check that temp folder exists, if not, create it
    If NOT (oWriteObj.FolderExists(strTempDir)) Then
    oWriteObj.CreateFolder(strTempDir)
    End If

    '*********Prepare to Write errors to Pipe delimited CSV file**
    'if file does not exist, create it
    If not(oWriteObj.FileExists(strLogFile)) then
    Set oWriteLog = oWriteObj.CreateTextFile(strLogFile, True)
    'write headings
    oWriteLog.WriteLine("Date,Error,BOI Error")
    else
    set oWriteLog = oWriteObj.OpenTextFile(strLogFile, 8, True)

    End If
    '*************************************************************
    ' The strLine variable is written to the output file
    strLine = DateStamp & "," & sErrorMessage & "," & sBOIerror
    oWriteLog.WriteLine(strLine)

    oWriteLog.Close
    End If
    End Sub

  • 0 in reply to n0tgunshy1

    Does it give you any more detail than just error 538? i don't recognize that one off the top of my head.

    What happens if you change that line from "retval = oSO.nMoveNext()" to just "oSO.nMoveNext"?

    Also, according to ProvideX docs, any error over 256 is an operating system error. So you may need to try capturing more info about the error at the time. Try trapping the error with a On Error Resume Next structure. Make sure to clear the error object first (Err.Clear) so you can trap it and if you do trap it, make sure to get the Err.Number, Err.Description, and Err.Source values.

    It also wouldn't hurt to check the oSO.sLastErrorMsg and oSO.sLastErrorNum when you are trapping the error too.

  • 0 in reply to David Speck

    Thanks for your response, David.  I will try the on error resume next.  Good idea.  The error also occurs with just the "oSO.nMoveNext."  I'll get the details of the error when I give it another go.  Thanks again!