Link to home
Start Free TrialLog in
Avatar of bfuchs
bfuchsFlag for United States of America

asked on

How can I change the code to use default browser?

Hi Experts,

I have the following code that opens TripPlanner with IE submitting Origin & dest addresses.

Would like to change it that should work for any type of browser (preferable users default browser), what does it entails?

Private Sub OpenTripPlanner(sOrigin As String, sDestination As String)
    DoCmd.Hourglass True
    Dim ie As Object, frm As Object
    Set ie = CreateObject("InternetExplorer.Application")
    ie.navigate "http://tripplanner.mta.info/MyTrip/ui_web/customplanner/tripplanner.aspx"
    Do While ie.busy Or ie.ReadyState <> 4
        DoEvents
    Loop
    Set frm = ie.Document.Forms(1)

    Wait 100
    
    frm("txtOriginInput").Value = sOrigin
    frm("txtDestinationInput").Value = sDestination
    ie.Document.ParentWindow.execScript ("submitAddresses()")
    ie.Visible = 1 'KishoreEnd Sub
    DoCmd.Hourglass False

End Sub

Open in new window

Avatar of Dr. Klahn
Dr. Klahn

Avatar of bfuchs

ASKER

@Dr. Klahn,

Both pages bring up this question, however I see no solution provided there to cover the code I posted.

As someone concluded on second page.
Just opening a URL by another browser may not meet your needs. If you are going to use the MSIE objects, methods and properties, you need that object.

Thanks,
Ben
I did not see a solution in those links either ... nor do I have one, sorry
Here's some code written by Leith Ross

'Written: June 09, 2010
'Author: Leith Ross
'Summary: Opens a web site using the default web browser

 Private Declare Function ShellExecute _
  Lib "Shell32.dll" _
    Alias "ShellExecuteA" _
     (ByVal hWnd As Long, _
      ByVal lpOperation As String, _
      ByVal lpFile As String, _
      ByVal lpParameters As String, _
      ByVal lpDirectory As String, _
      ByVal nShowCmd As Long) As Long

Function OpenURL(ByVal WebAddress As String)

  Dim Msg As String
  Dim RetVal As Long
  
    RetVal = ShellExecute(0&, "open", WebAddress, vbNullString, vbNullString, 1&)

    If RetVal <= 32 Then
       Select Case RetVal
         Case 2     'SE_ERR_FNF
           Msg = "File not found"
         Case 3      'SE_ERR_PNF
           Msg = "Path not found"
         Case 5      'SE_ERR_ACCESSDENIED
           Msg = "Access denied"
         Case 8      'SE_ERR_OOM
           Msg = "Out of memory"
         Case 32     'SE_ERR_DLLNOTFOUND
           Msg = "DLL not found"
         Case 26     'SE_ERR_SHARE
           Msg = "A sharing violation occurred"
         Case 27     'SE_ERR_ASSOCINCOMPLETE
           Msg = "Incomplete or invalid file association"
         Case 28     'SE_ERR_DDETIMEOUT
           Msg = "DDE Time out"
         Case 29     'SE_ERR_DDEFAIL
           Msg = "DDE transaction failed"
         Case 30     'SE_ERR_DDEBUSY
           Msg = "DDE busy"
         Case 31     'SE_ERR_NOASSOC
           Msg = "Default Email not configured"
         Case 11     'ERROR_BAD_FORMAT
           Msg = "Invalid EXE file or error in EXE image"
         Case Else
           Msg = "Unknown error"
       End Select
    Else
       Msg = "OK"
    End If

    OpenURL = Msg
    
End Function



Private Sub Worksheet_Change(ByVal Target As Range)

  If Target.Count > 1 Then Exit Sub
  
    If Not Intersect(Target, Range("B1")) Is Nothing Then
       If Target.Value = 1 Then Call OpenURL(Range("A1"))
    End If
    
End Sub

Open in new window


Using the example above, A1 should contain the target URL
Avatar of bfuchs

ASKER

@Roy,

Your code seems basically to just opens a given site, (something like the build-in FollowhHperlink does in Access), However dont see how to handle the preceding code like
 
Set frm = ie.Document.Forms(1)
 
    frm("txtOriginInput").Value = sOrigin
    frm("txtDestinationInput").Value = sDestination
    ie.Document.ParentWindow.execScript ("submitAddresses()")

Open in new window


Thanks,
Ben
Avatar of bfuchs

ASKER

Hi Experts,

The reason users are requesting a different browser is due to the time IE takes to load this page, according to them Chrome (or other browsers) works much faster, so perhaps if you have a way I can accelerate this process will also be of a help-:)

Thanks,
Ben
How often do they dump their temporary files?
Avatar of bfuchs

ASKER

Hi,

I'm not sure but is this something only related to IE?

I can ask them to remove once all their Temp internet files and see how this matters.

Thanks,
Ben
A weakness in the filesystem is that, once there are too many files in a given folder, its performance falls through the floor (This dates back to MS_Dos).  Dumping the temporary files can often triple the speed of a browser and Chrome isn't immune, either.
\Windows\Temp is also a good folder to empty.
Avatar of bfuchs

ASKER

OK I did ask users to try cleaning up their temp files, will wait a couple of days to see if that helps.

..and Chrome isn't immune, either.
Well as you see thread above, users were saying that other browsers are performing much better (at least for this particular task).

Therefore I need either a solution to speed up this with IE or a way to convert the code to use a different browser as OP.

Thanks,
Ben
Do you use any active-x controls or java in your app?
If you do, it may not work in another browser.
Avatar of bfuchs

ASKER

Hi,

At the moment we dont use any of these..

I'm out of the office, will resume next week.

Have a nice weekend!

Thanks,
Ben
Avatar of bfuchs

ASKER

@Davis,

According to user, after clearing history still IE takes much longer than other browsers, what do you suggest I try nect?

Thanks,
Ben
It seems to me then, that you will need to build the string, including the URL and then pass that to the browser as the address.  Any other avenue will make us vulnerable to the quirks of that browser.
i.e. https://www.google.com/maps/dir/Matthews,+NC+28104/Portland,+OR
Avatar of bfuchs

ASKER

Hi,

this is not the case with the site we are looking for as OP "http://tripplanner.mta.info/MyTrip/ui_web/customplanner/tripplanner.aspx"

With this site, the URL does not get changed when you submit the searching criteria, and this is why we are forced to use the code as posted.

Thanks,
Ben
Since I haven't really used Basic for almost 40 years, now, I can't help with that.  You will; though, have issues with each browser so you had better start by detecting it.
Avatar of bfuchs

ASKER

Hi,

At the moment I gave over to someone more senior in our office to work at that, will keep posted if have any progress.

Thanks,
Ben
This is fundamentally impossible, since the form in the webpage is using POST rather than GET; which means that you must use browser's object model in order to submit it, so it must be specific browser.

Opening URL with parameters in default browser is possible for GET forms; however, note the following, taken from http://stackoverflow.com/questions/3477333/what-is-the-difference-between-post-and-get/3477374#3477374 :

Finally, an important consideration when using GET for AJAX requests is that some browsers - IE in particular - will cache the results of a GET request. So if you, for example, poll using the same GET request you will always get back the same results, even if the data you are querying is being updated server-side. One way to alleviate this problem is to make the URL unique for each request by appending a timestamp.

i.e. even if it was possible, you might hit the problem of the browser caching the trip, so for the same origin and destination it would always return the same trip regardless of the time.
Avatar of bfuchs

ASKER

Hi Vadim,

which means that you must use browser's object model in order to submit it, so it must be specific browser.
How about if I would want to choose chrome as the browser for this task is that possible? can I have access to its object modules as well?

you will always get back the same results..
So far didn't got any complaints re this, so I'm not so concerned about it.

Thanks,
Ben
Here's Chrome development portal:
developer.chrome.com

I'm pretty sure there would be nothing even distantly compatible with COM object, i.e. usable in desktop applications. Microsoft was doing it because that's how they were increasing the value of Microsoft Office for business customers. Google does not have anything like that on the agenda.

> So far didn't got any complaints re this, so I'm not so concerned about it.

Because so far you have not implemented it - that is, opening the target page by sending just a URL with parameters, which would be opened by whatever browser is the default.
Avatar of bfuchs

ASKER

Because so far you have not implemented it - that is, opening the target page by sending just a URL with parameters..
You mean to say, this problem will only occur if I'm open for other browsers, while if I stick to my current code OP then its fine?

BTW, as described above, the reason I am looking to change browsers is due to the slowness of IE compared to others, in particular when dealing with this site, therefore a suggestion how to accelerate the process would also be acceptable.

Thanks,
Ben
Your current code is using POST rather than GET (if you are not very familiar with the difference, you have to read about it in Wikipedia or many other sources, it's crucial to understand). If the result may be different every time you send the request, you must use POST.

However, in order to use POST, you must have access to the object model of the browser. To use GET, you don't have to, because you can send GET in one URL with parameters.

For example, in order to make a lookup of a postal address, GET is OK because the result of the same request will be the same every time - which means that you can use a URL like Waze does, for instance, with latitude and longitude being the parameters.

But for something like weather report, it has to be POST, because browser may cache the result of GET, which will result in the same weather report every time while the result remains in browser's cache.

This consideration, however, is rather a guideline for the website owner rather than for the visitor. The visitor can use what's available, i.e. if website owner has programmed his website to accept URL parameters, then website user can use them. If he did not then he can't.

TripPlanner has not provided any parameters. Whoever has created the very first code you posted in this question, has reverse-engineered the webpage that is sending the request, figured out that it's using script "submitAddress", and programmed it. He was able to do it only because Microsoft has created an object model for their browser.

Rather than messing with the browser (which is usually unreliable because sooner or later the website will change their design, which will ruin your solution), I would look for developer-oriented resources of the same site - such as http://web.mta.info/developers/. They mention "datafeeds", so perhaps that's what you need.

If they don't, then perhaps the same Google may help. Since Google Maps provide public transportation schedules, chances are, their Google Places webservice you are already familiar with will give you the same data as you obtain from MTA.
Avatar of bfuchs

ASKER

Hi Vadim,

I see what you are saying regarding data changes in web server site, however from my understanding, users are using it for getting directions from one place to the other or just to find out what is the distance between two locations, and in these cases it would not be something that keeps changing.

Rather than messing with the browser (which is usually unreliable because sooner or later the website will change their design
You right, if I would be doing it now definitely would look at this direction first, however since its done already and so far working, will leave it for now.

Regarding this question, guess I will wait to see what our consultant comes up with, (the one who originally helped us getting it work as posted) perhaps he may come up with a solution and I will keep you all posted.

Thanks,
Ben
> and in these cases it would not be something that keeps changing.

Quite likely, but as I said, whether to use GET or POST, is the decision of the website developer. My considerations about caching etc. were only what he _might_ have taken into account. For you, what's important is the final result: this particular website accepts only POST, which means that sending all information in the URL with parameters (which would be accepted by any browser, being a standard) is impossible, which means that you need access to the programmatic object representing the browser, which means using IE.
...still, one somewhat ugly way to accomplish that is:

1. using IE model, programmatically send POST
2. obtain the response with HTML of the result
3. save HTML into a local file (with the images; perhaps IE has a single method for that)
4. Run the URL of the local HTML file - it will open it in default browser.
Avatar of bfuchs

ASKER

1. using IE model, programmatically send POST

Since the whole purpose of changing the browser is due to slowness of IE, how would that help as I'm still relying on it?

Thanks,
Ben
It probably wouldn't, although taking into account that the last thing the user would see would be fast Chrome (for example), and it's the last thing that eventually matters, subjectively the user might become happier. This probably might be a matter of a study in psychology :-)

Speaking of the gig project - further improvement might be along the lines of having the address validated, probably at yet another third party, before submitting it to google. Google tends to interpret even completely bogus addresses, and I actually saw it "finding" misspelled address half across the country, and returning success.
Avatar of bfuchs

ASKER

I would look for developer-oriented resources of the same site..
Actually this may be a solution for it, as it will not be using any browser if I understand correctly..?
subjectively the user might become happier.
maybe but I doubt it will pass our testing stage, as they are closely looking at the timing matter..
further improvement might be along the lines of having the address validated
Great, this may be a good idea regardless of that project, as they should have all addresses checked for validation right away when its being entered..I will suggest it for them.
probably at yet another third party,
Is there someone in particular you would recommend?

BTW, thanks again for the project, I just finished integrating with our app, hope users will love it..

Thanks,
Ben
> probably at yet another third party,
> Is there someone in particular you would recommend?

I have my own solutions at my company, but they are not as easy as geolocation.
USPS does it, for free, but they want to be sure that this is only with the purpose of mailing something by USPS. When I did it, they actually requested pieces of code for their review. In this light, using their free service for your purpose probably would be illegal.

Fedex does free address validation as well, including international, but you must have an account and developer key. They don't require a shipment however.

Same with UPS, but only domestic addresses.

AddressDoctor provides probably the best international validation, but it's not free.
====================================

Regarding the points - since I eventually did the gig project, the points are probably mine :)
Avatar of bfuchs

ASKER

Hi Vadim,

Same with UPS, but only domestic addresses.
we only need it for domestic addresses, so in this case you think would be legal to use your code?

Regarding the points - since I eventually did the gig project..
Well you got the points on the question related to that gig:), however in this case, as mentioned earlier I'm waiting for our consultant to finish his work & then will finalize, unless of course you guys come up with a working solution..

Thanks,
Ben
>  so in this case you think would be legal to use your code?

The matter with USPS was not whether it was domestic or not, but whether their tax-funded service was going to be used for shipping by USPS, so tax dollars wouldn't be used for private business gain.

Whether particular usage of particular service is legal, is probably found in the legal agreement when you apply for the developer's key.
Avatar of bfuchs

ASKER

Hi Vadim,

Just updating..

Looks like our guy found a way to do it using selenium wrapper.

I will keep posted once he finalize it.

Thanks,
Ben
So the solution with the API that I created was not useful? curious why.
Avatar of bfuchs

ASKER

Hi Vadim,

Just to summarize, I had two issues posted, one was how to get the waze site to open with pre-defined addresses, and that is what I ended up creating a GIG project for, and that is what you created the API for..https://www.experts-exchange.com/questions/28963735/how-to-open-Waze-com-livemap-from-address-saved-in-DB.html
(btw, At that time users approve it & didnt hear any complaints since, assuming its working.)

Now this question as is it says "How can I change the code to use default browser", has nothing to do with that (to my understanding, pls correct me if I'm wrong).

Thanks,
Ben
I thought it's about one and the same project, so maybe I was confused. Glad it's working.
ASKER CERTIFIED SOLUTION
Avatar of bfuchs
bfuchs
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bfuchs

ASKER

@Vadim,

As an btw, in order to integrate this with our app its necessary to install first the selenium in all desktops, as the module has a reference for that library.

I was wondering, if there is a way to use late binding vs early binding in order to avoid errors if they try to open the app before the selenium program gets installed?

Thanks,
Ben
Avatar of bfuchs

ASKER

At this point I'm closing this question as I will be on vacation for the next 10 days, perhaps will open a new thread upon my return in order to finalize..

Thanks to all participants!