I am trying to use vba (Access 2013) to automate a route finder website (https://www.theaa.com/driving/mileage-calculator.jsp) I have some working code that on a form command button allows me to; open an external instance of internet explorer (as apposed to a browser control), enter postcode/address information from my db, click a link that adds further destination fields if required, Change cost per mile default from a text box on my form, click a button called "Get Route". When "Get Route" is clicked this produces a page with the results of the search, which include a static google map with the route steps marked on a purple line A B C etc. I want to capture this image and use in my db form using a webbrowser or image field control so I can use it in a report when I have conducted searches for the most economical route. I have looked at the DOM Explorer and source code but I cant work out how to do this or if it possible? There is a div "gmnoprint" that is highlighted when the map is selected and in the source code there is a reference to "mapContainer" which seems to be in the right area of the sequence of actions/results. I don't know how to drill through the reference and create code which will allow me to put the map in my form. The selection of code I have posted is one part of a select case which determines what can be entered into my text boxes, the google map image code would presumably go in where indicated? I would say I am an enthusistic learner and a moderate user without any formal training. I would very much appreciate any replies.
Dim IE As New InternetExplorer
Dim doc As HTMLDocument
Dim RDate As String
On Error GoTo Errorhandler
RDate = Me.TxtRouteDate
'................................................................
Select Case Me.TxtNoSum
Case Is = IsNull(Me.TxtPC1) Or IsNull(Me.TxtPC2)
MsgBox "Please Enter at least 2 Postcodes"
Case Is <= 2
MsgBox "Please Enter at least 2 Postcodes"
Case Is = 3
IE.Visible = True
IE.Navigate "https://www.theaa.com/driving/mileage-calculator.jsp"
IE.Top = 20
IE.Left = 50
IE.Height = 1300
IE.Width = CInt(Int((1000 * Rnd()) + 1))
While IE.Busy
DoEvents
Wend
Set doc = IE.Document
With doc
'Clears previous searches
doc.all("mcDeleteRoutesLink").Click
'Inserts info into web site text boxes.
doc.getElementById("RouteDate").Value = RDate
doc.getElementById("RouteFrom").Value = Me.TxtPC1
doc.getElementById("RouteTo").Value = Me.TxtPC2
doc.getElementById("fuelPricePerLitre").Value = Me.TxtPPL
End With
While IE.Busy
DoEvents
Wend
'Clicks "Get Route" Button
Dim btn As Object
Set btn = doc.getElementById("getRouteWrapper").Children(0)
If Not btn Is Nothing Then
btn.Click
While IE.Busy
DoEvents
Wend
' Inserts distance recorded by aa mileage calculator into text control on my
form
Set htmlDist = doc.all("routeDistanceTotal")
If Not htmlDist Is Nothing Then
Me.TxtDistance = htmlDist.innerText
'google image code to go here after map page loads?
End If
End If
(Next Case)
Aucun commentaire:
Enregistrer un commentaire