0

In the below code I am extracting data from SAP. In a few SAP reports I am running, occasionally data is not available, in which a pop up box appears, displaying

No Data Exists For Chosen Selection

I've implemented the below error handling strategy, which works fine when debugging and stepping into the code, but running in totality I receive this error on the asterik denoted line:

The Control Could Not Be Found By ID

session.findById("wnd[0]/tbar[1]/btn[8]").press

On Error GoTo ResumeInterCompany
**If session.findById("wnd[1]/tbar[0]").Text = "No data exists for chosen selection" Then**
GoTo TroubleShootInterCompany

End If

Any suggestions. I can provide more relevant code if need be.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Reed
  • 11
  • 2
  • 4
  • There's no toolbar at index 0? Where's no window at index 1? FWIW there's 100% a better way to do whatever you're trying to do, than using `GoTo` jumps. – Mathieu Guindon Oct 06 '17 at 18:46
  • You should check to make sure your findById method returns a object, before trying to click it. – Ryan Wildry Oct 06 '17 at 20:56

1 Answers1

0

My workaround is as follows:

session.findById("wnd[0]/tbar[1]/btn[8]").press

On Error Resume next
myText = "x"
err.clear 
myText = session.findById("wnd[1]/tbar[0]").Text
if err.number <> 0 then myText = ""
on error goto 0
If myText = "No data exists for chosen selection" Then
   GoTo TroubleShootInterCompany
End If

Regards, ScriptMan

ScriptMan
  • 1,580
  • 1
  • 9
  • 9