Solved

How can I change the code to use default browser?

Posted on 2016-08-17
39
97 Views
Last Modified: 2016-10-18
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

0
Comment
Question by:bfuchs
  • 20
  • 11
  • 5
  • +3
39 Comments
 
LVL 23

Expert Comment

by:Dr. Klahn
ID: 41760358
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41760503
@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
0
 
LVL 75
ID: 41760521
I did not see a solution in those links either ... nor do I have one, sorry
0
 
LVL 17

Expert Comment

by:Roy_Cox
ID: 41760548
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
1
 
LVL 3

Author Comment

by:bfuchs
ID: 41761625
@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
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41761700
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
0
 
LVL 42

Expert Comment

by:Davis McCarn
ID: 41779736
How often do they dump their temporary files?
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41780520
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
0
 
LVL 42

Expert Comment

by:Davis McCarn
ID: 41780704
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.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41780969
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
0
 
LVL 42

Expert Comment

by:Davis McCarn
ID: 41781396
Do you use any active-x controls or java in your app?
If you do, it may not work in another browser.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41782189
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
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41784100
@Davis,

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

Thanks,
Ben
0
 
LVL 42

Expert Comment

by:Davis McCarn
ID: 41784590
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
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41785327
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
0
 
LVL 42

Expert Comment

by:Davis McCarn
ID: 41785899
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.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41787191
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
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 41797284
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.
1
 
LVL 3

Author Comment

by:bfuchs
ID: 41798817
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
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 41798958
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.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41799069
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
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 41800943
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.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41805681
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
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 41805765
> 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.
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 41805770
...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.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41805834
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
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 41807785
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.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41807958
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
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 41829829
> 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 :)
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41830899
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
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 41831006
>  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.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41836139
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
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 41836273
So the solution with the API that I created was not useful? curious why.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41836341
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
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 41837129
I thought it's about one and the same project, so maybe I was confused. Glad it's working.
0
 
LVL 3

Accepted Solution

by:
bfuchs earned 0 total points
ID: 41842833
Hi Vadim,

As mentioned our guy is working on something like the following
1-Installing the selenium wrapper
2- running the following code
Option Explicit

'##################################################################################################################
'Verify the page title for each link defined in the range "MyValues" and write the result in the 3rd column
'##################################################################################################################

Public Sub TC001_VerifyLinksTitles()
   Dim driver As New SeleniumWrapper.WebDriver


    driver.Start "chrome", "http://tripplanner.mta.info/MyTrip/ui_web/customplanner/tripplanner.aspx"  'Starts the browser


    driver.Open "http://tripplanner.mta.info/MyTrip/ui_web/customplanner/tripplanner.aspx"    'Opens the finance page
    
     Dim data1, data2
    driver.findElementById("txtOriginInput").Clear
    driver.findElementById("txtDestinationInput").Clear

    driver.findElementById("txtOriginInput").SendKeys ("1 Broadway, New York, NY 10004")
 driver.findElementById("txtDestinationInput").SendKeys ("250 Broadway, New York, NY 10007")

driver.executeScript ("submitAddresses()")

' driver.stop 'Stops the browser                   'Stop the browser
End Sub

Open in new window

So far it started to work, however we have some minor issues..-:(
for example, the attached is popping up every time we use it.

Thanks,
Ben
Untitled.png
0
 
LVL 40

Assisted Solution

by:Vadim Rapp
Vadim Rapp earned 500 total points
ID: 41842891
Quite frankly, before this thread I never heard neither about selenium wrapper, nor about chromedriver, so I definitely learn something new here :-) From what I figure (from https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver), googledriver and selenium are parts of the same "package" intended to programmatically manipulate web browser. So if at some point googledriver is starting, it's probably normal.

I think, the best way to address any problems with it is by creating an "issue" at https://github.com/SeleniumHQ/selenium/issues, where you have direct access to the developers.
0
 
LVL 3

Author Comment

by:bfuchs
ID: 41843038
@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
0
 
LVL 3

Author Closing Comment

by:bfuchs
ID: 41847917
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!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Read about why website design really matters in today's demanding market.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now