Mitchellstokes
New Member
- Joined
- Nov 2, 2014
- Messages
- 4
Hey Guys,
I've been running a VBA script from Microsoft Access that looks up an ABN number from the ABN lookup website.
It appears that an upgrade to ie10 may have ruined the script. It fails at "Set contentmajor=ie.Document.getelementbyid("content-major")" with error: "Run-time error '-2147467259 (80004005)': Method 'Document' of object 'iWebBrowser2' failed.
I've had a look online but I'm not that familiar with this type of code.
I've been running a VBA script from Microsoft Access that looks up an ABN number from the ABN lookup website.
It appears that an upgrade to ie10 may have ruined the script. It fails at "Set contentmajor=ie.Document.getelementbyid("content-major")" with error: "Run-time error '-2147467259 (80004005)': Method 'Document' of object 'iWebBrowser2' failed.
Code:
Option Compare Database
Private Sub CheckABRButton_Click()
Dim ie As Object
Dim fromStart, toStart, readLength, contentMajorStart As Variant
Dim abnDetails As Object
Dim contentMajor As Object
Dim searchNumber, entityName, entityType, ACN, businessLocation, status As String
If Len(f_abrABNACN) > 0 Then
searchNumber = Replace(f_abrABNACN, " ", "")
Else
searchNumber = ""
End If
If Len(searchNumber) = 11 Or Len(searchNumber) = 9 Then
Set ie = CreateObject("internetexplorer.application")
ie.Visible = False
ie.navigate "[url=http://abr.business.gov.au/SearchByAbn.aspx?SearchText]ABN Lookup -[/url]=" & searchNumber
While ie.busy
DoEvents
Wend
Set contentMajor = ie.Document.getelementbyid("content-major")
'MsgBox contentMajor.innerHTML
If contentMajor Is Nothing Then
MsgBox "Request to ABR failed. There might be too much network traffic at this time. Please try again."
ie.Quit
Exit Sub
Else
contentMajorStart = InStr(contentMajor.innerhtml, "process-error")
End If
If contentMajorStart > 0 Then
f_abrEntityName = ""
f_abrEntityType = ""
f_abrACN = ""
f_abrPostCode = ""
f_abrStatus = ""
CopyDetailsButton.Visible = False
MsgBox "The details you provided couldn't be found in the ABR. Please re-check them and try again."
Else
Set abnDetails = ie.Document.getelementbyid("abn-details")
If abnDetails Is Nothing Then
MsgBox "Request to ABR failed. There might be too much network traffic at this time."
ie.Quit
Exit Sub
End If
' Get entityName - was 40 shift, depends on version of IE!
fromStart = InStr(abnDetails.innerhtml, "Entity name:") + 23
toStart = InStr(fromStart, abnDetails.innerhtml, "</td>")
readLength = toStart - fromStart
entityName = Trim(Mid(abnDetails.innerhtml, fromStart, readLength))
f_abrEntityName = entityName
' Get entityType
fromStart = InStr(abnDetails.innerhtml, "href=""/EntityTypeDescription.aspx?Id=")
If fromStart <= 0 Then
fromStart = InStr(abnDetails.innerhtml, "Entity Type:") + 43
toStart = InStr(fromStart, abnDetails.innerhtml, "</td>")
Else
fromStart = fromStart + 44
toStart = InStr(fromStart, abnDetails.innerhtml, "</a>")
End If
readLength = toStart - fromStart
entityType = Trim(Mid(abnDetails.innerhtml, fromStart, readLength))
f_abrEntityType = entityType
' Get ACN
If entityType = "Australian Private Company" Then
fromStart = InStr(abnDetails.innerhtml, "searchType=OrgAndBusNm") + 38
ACN = Trim(Mid(abnDetails.innerhtml, fromStart, 9))
f_abrACN.Visible = True
f_abrACN = ACN
Else
f_abrACN = ""
f_abrACN.Visible = False
End If
'Get Business Location - was 40 shift, depends on version of IE!
fromStart = InStr(abnDetails.innerhtml, "location:") + 23
toStart = InStr(fromStart, abnDetails.innerhtml, "</td>")
readLength = toStart - fromStart
businessLocation = Trim(Mid(abnDetails.innerhtml, fromStart, readLength))
'f_abrPostCode = Split(businessLocation, " ")(1)
f_abrPostCode = businessLocation
'Get Status - was 35 shift, depends on version of IE!
fromStart = InStr(abnDetails.innerhtml, "status:") + 18
toStart = InStr(fromStart, abnDetails.innerhtml, "</td>")
readLength = toStart - fromStart
status = Trim(Mid(abnDetails.innerhtml, fromStart, readLength))
f_abrStatus = Split(status, " ")(0)
CopyDetailsButton.Visible = True
End If
ie.Quit
Else
MsgBox "You need to enter a valid ABN or ACN to continue. ABNs are 11 digits, ACNs are 9 digits."
End If
End Sub
I've had a look online but I'm not that familiar with this type of code.