How to use Err.Clear correctly

0

Good afternoon, guys.

This is my first question here in the forum, so I apologize if it is not easy to understand my doubt.

Next, I have a script that automates nfs approvals in SAP , but within the loop once it has finished approving, it will no longer find the "ID "of the object to click generating the error.

I made a " On error goto Feito " where as soon as it enters there executes the "Err.Clear" and a msgbox appears asking if the error is of position, if it is yes, it executes from another part of the code, and so the looping continues, but even with " Err.Clear " it does not clear the last error, making it impossible for the MsgBox to always appear for the user to check the error and thus continue the script, the error will always be the same, you will not find the "ID" of the object. In short, I wanted to know how I can do that whenever I give the error, it clears the last error given, and as soon as it goes again, instead of stopping to debug it, go back to the msgbox and continue the looping.

The code is a sub, I'll put some snippets to exemplify:

Sub DL_ZNFE_MAIN()
On Error GoTo Feito:
Dim resultado As VbMsgBoxResult
var_sap_session.findById("wnd[0]/tbar[0]/okcd").Text = "znfe" 
var_sap_session.findById("wnd[0]").sendVKey 0

This is the first section, basically it will enter into a transaction, put some inputs, and done this will appear several notes, which will be accessed by this code:

For i = 0 To 30


var_sap_session.findById("wnd[0]/usr/tblZKFBC_MONITOR_NFETC_SINTESE/txtT_SINTESE-DOCNUM[1,0]").SetFocus
var_sap_session.findById("wnd[0]/usr/tblZKFBC_MONITOR_NFETC_SINTESE/txtT_SINTESE-DOCNUM[1,0]").caretPosition = 0
var_sap_session.findById("wnd[0]").sendVKey 2
var_sap_session.findById("wnd[0]/usr/btnSWE19").press
var_sap_session.findById("wnd[0]/tbar[1]/btn[8]").press

But when giving error, it comes to this part:

Feito:
Err.Clear
resultado = MsgBox("O erro é de posição?", vbYesNo, "Erro")
If resultado = vbYes Then
    var_sap_session.findById("wnd[2]/usr/lbl[43,3]").SetFocus
    var_sap_session.findById("wnd[2]/usr/lbl[43,3]").caretPosition = 3
    var_sap_session.findById("wnd[2]").sendVKey 2
    var_sap_session.findById("wnd[0]").sendVKey 2
    GoTo Continue
Else
Err.Clear
var_sap_session.findById("wnd[0]/tbar[1]/btn[6]").press
MsgBox "Não foi possivel encontrar notas rejeitadas."

End If

Then after arriving at the error, it will appear the msgbox that will ask if the error is of position or not, if yes it will go to "Continue":

Continue:
    var_sap_session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/txtSVALD-VALUE[2,21]").Text = "0.00"
    var_sap_session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/txtSVALD-VALUE[2,21]").SetFocus
    var_sap_session.findById("wnd[1]/usr/sub:SAPLSPO4:0300/txtSVALD-VALUE[2,21]").caretPosition = 4
    var_sap_session.findById("wnd[1]/tbar[0]/btn[0]").press

And so it will continue the looping within this FOR, but if for some reason it gives error again, instead of generating the msgbox again, it already for the code.

    
asked by anonymous 11.09.2018 / 19:19

0 answers