Private Sub CheckEntered()
Dim IE As InternetExplorerMedium
Dim targetURL As String
Dim lastrow As Long, ws As Worksheet
Dim selectElement As HTMLSelectElement
Dim optionIndex As Integer
Dim lRow As Long
Dim x As String
Dim isa As String
Dim i As Integer
Dim errRow As Long
tryAgain:
lRow = ThisWorkbook.Sheets("Sheet2").Range("P" & Rows.Count).End(xlUp).Row + 1
targetURL = "myurl"
Set IE = New InternetExplorerMedium
IE.Visible = False ' Set to true to watch what's happening
IE.Navigate targetURL
'__________________________________________________________
'*** ***
'*** Navigates to the appropriate sample type in Pi ***
'*** ***
'__________________________________________________________
Do Until IE.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
i = Me.lb_type.ListIndex
If lb_type.Selected(i) = True Then
IE.Document.getElementById("ddlSelection").selectedIndex = i + 1
IE.Document.getElementById("ddlSelection").FireEvent ("onchange")
Do
DoEvents
Loop While IE.Document.getElementById("Sample_Arrival_Time") Is Nothing And IE.Document.getElementById("txtMessage") Is Nothing
End If
'______________________________________________________________________________________
'*** ***
'*** Compares last entered sample in worksheet to the last entered sample in Pi ***
'*** ***
'______________________________________________________________________________________
Set ws = ThisWorkbook.Sheets(i + 2)
lastrow = ws.Range("C" & Rows.Count).End(xlUp).Row
On Error GoTo errHandler:
If lb_type.Selected(2) = True Then
isa = IE.Document.getElementById("IsaDate")(1).Text
Else
x = IE.Document.getElementById("ListBox1")(1).Text
End If
If isa = "" Then
If Not ws.Cells(lastrow, 3).Text = x Then
ThisWorkbook.Sheets("Sheet2").Cells(lRow, "P") = Me.lb_type & ": " & x & " triggered error."
ThisWorkbook.Sheets("Sheet2").Cells(lRow, "Q") = Me.cb_analyst.Text
With Me.lb_type
If .Selected(0) = True Then efs_Web
If .Selected(1) = True Then efmWeb
If .Selected(2) = True Then isaWeb
If .Selected(3) = True Then convWeb
If .Selected(4) = True Then revWeb
If .Selected(5) = True Then feedWeb
If .Selected(6) = True Then otherWeb
End With
MsgBox "Please check Pi to make sure the last sample went into Pi."
End If
Else
If Not ws.Cells(lastrow, 3).Text = isa Then
ThisWorkbook.Sheets("Sheet2").Cells(lRow, "P") = Me.lb_type & ": " & isa & " triggered error."
ThisWorkbook.Sheets("Sheet2").Cells(lRow, "Q") = Me.cb_analyst.Text
isaWeb
MsgBox "Please check Pi to make sure the last sample went into Pi."
End If
End If
IE.Quit
Set IE = Nothing
Exit Sub
errHandler:
errRow = ThisWorkbook.Sheets("Sheet2").Range("R" & Rows.Count).End(xlUp).Row
With ThisWorkbook.Sheets("Sheet2")
.Range("R" & errRow + 1) = "Went to error handler"
.Range("S" & errRow + 1) = Now
.Range("T" & errRow + 1) = Err.Number & ": " & Err.Description
End With
Resume tryAgain:
End Sub