application.followhyperlink (memory leak?)

Respondida application.followhyperlink (memory leak?)

  • jueves, 12 de abril de 2012 23:46
     
     

    I have function that I call like this from a click event of a button on a form that is linked to a table with lat/long and zoom level fields

        If Not IsNull(Me.LatInDegreesN) And Not IsNull(Me.LongInDegreesW) And Not IsNull(Me.ZoomLevel) Then
            Application.FollowHyperlink bingMapIt (Me.LatInDegreesN, Me.LongInDegreesW, Me.ZoomLevel)
        Else
            MsgBox "need latitude,longitude and zoom level to map location"
        End If

    My function is this:  (I've removed the error routine to minimize what you need to look at here) 
    Function bingMapIt(dblLat As Double, dblLong As Double, intZoom As Integer) As String
        Dim strURL As String
        Dim strBaseURL As String
        Dim strBingParams As String
        Dim strLat As String
        Dim strLong As String
        Dim strZoomLevel As String
        
        If IsNull(dblLat) Or IsNull(dblLong) Or IsNull(intZoom) Then GoTo Exit_Sub
        
        'Example URL- http://bing.com/maps/default.aspx?cp=47.60113~-115.79804&lvl=15&rtp=pos.47.60_-115.79
        strBaseURL = "http://bing.com/maps/default.aspx?"
        strZoomLevel = Trim(Str(intZoom))
        strLat = Trim(Str(Abs(dblLat)))    'Northern Hemisphere Only (positive)
        strLong = "-" & Trim(Abs(dblLong)) 'Western Hemisphere Only  (negative)
        strBingParams = "cp" & strLat & "~" & strLong & "&lvl=" & strZoomLevel & "&rtp=pos." & strLat & "_" & strLong
        strURL = strBaseURL & strBingParams
        
        bingMapIt = strURL
       
    End Function

    The problem is:

    When entering lat / long / zoom field on this form and then saving and clicking on the button to follow the hyperlink everything works just fine for about the first 20 or so records of doing this, and then I get no response and have to close (via the task manager) both access and internet explorer.  Is there something in my code that is causing this phenomenon?  I should mention that only one instance of IE is open with multiple tabs opening upon each click of the button, however periodically I close tabs on IE so that too many do not accumulate.

    In addition to running both Access and Internet Explorer, I have arcGIS Desktop running (this is a resource hog application by ESRI), but the only applications that do not respond are Access and IE. 

    Another question that I have is Firefox is my default browser, however when this call is made, it opens IE.  Is there a way to force the call to use the default browser of the system it is running on?


    For the benefit of others, please mark posts as answered or helpful when they answer or assist you in finding the answer. ___ "We came all this way to explore the Moon, and the most important thing is that we discovered the Earth." - Bill Anders, Apollo 8.



    • Editado -suzyQ jueves, 12 de abril de 2012 23:47
    • Editado -suzyQ jueves, 12 de abril de 2012 23:49
    •  

Todas las respuestas

  • viernes, 13 de abril de 2012 2:49
     
      Tiene código

    I am not sure why it freezes, but I do know that IE will run multiple processes / instances of iexplore.exe, while FireFox only run one instance.

    So its quite possible that IE is consuming more memory then Firefox.

    When I did a test for opening 8 webpages in both browsers, IE totals 134 MB over 5 instances, while FireFox totals 80 MB over 1 instance.

    So with that said you can use the Shell() command to use/ launch FireFox with the link, for example:

    Dim strLink As String
    
    strLink = "http://www.microsoft.com/"
    
    Shell "C:\Program Files\Mozilla Firefox\firefox.exe " & strLink

    For Default Browser, check to make sure FireFox is running as Default Browser and you can change that in Default Programs in Windows.

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.

  • viernes, 13 de abril de 2012 5:23
     
      Tiene código

    Not the Explorer that freezes, it's the access waiting for response. In my example I'm using explorer to print html files change it for navigation it should work

    Private Function IexplorerPrint(fullPath As String)
        Dim MyIexplorerPrint As Object
        Const OLECMDID_PRINT = 6
        Const OLECMDEXECOPT_PROMPTUSER = 1
        Const OLECMDEXECOPT_DONTPROMPTUSER = 2
    
        On Error GoTo IexplorerPrint_err
        Set MyIexplorerPrint = CreateObject("InternetExplorer.Application")
        Call WaitForLoad(MyIexplorerPrint)
        MyIexplorerPrint.Navigate fullPath
        Call WaitForLoad(MyIexplorerPrint)
        MyIexplorerPrint.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER
        Set MyIexplorerPrint = Nothing
    
    IexplorerPrint_exit:
        Exit Function
    IexplorerPrint_err:
        MsgBox Err.Description
        Resume IexplorerPrint_exit
        Resume
    End Function
    
    Private Sub WaitForLoad(objIE As Object)
        Do While objIE.Busy
          DoEvents
        Loop
    End Sub
    

  • viernes, 13 de abril de 2012 14:47
     
     

    So with that said you can use the Shell() command to use/ launch FireFox with the link, for example:

    I use firefox, but not all the users that will be using this do.  I would like to be able to launch the default browser of the particular user of the system and not a specific browser, but I may have to given the issue with IE.

    For the benefit of others, please mark posts as answered or helpful when they answer or assist you in finding the answer. ___ "We came all this way to explore the Moon, and the most important thing is that we discovered the Earth." - Bill Anders, Apollo 8.

  • viernes, 13 de abril de 2012 15:10
     
     

    Another question that I have is Firefox is my default browser, however when this call is made, it opens IE.  Is there a way to force the call to use the default browser of the system it is running on?

    Are you sure about FF? I have Chrome as a default browser and Application.FollowHyperlink "http:\\www.ya.ru" opens this site in a new Chrome tab, not IE.

    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru

  • viernes, 13 de abril de 2012 15:18
     
     

    Not the Explorer that freezes, it's the access waiting for response. In my example I'm using explorer to print html files change it for navigation it should work

    OK, I modified my call to this (and using your WaitForLoad sub - I'm not sure why the loop on the doEvents though - I've never seen it that way)

            Set objIEForMap = CreateObject("InternetExplorer.Application")
            Call waitForLoad(objIEForMap)
            objIEForMap.navigate bingMapIt(Me.LatInDegreesN, Me.LongInDegreesW, Me.ZoomLevel)
            Call waitForLoad(objIEForMap)

    But now it opens three instances of IE (as seen in the task manager processes), but doesn't show of them.  What am I missing?

    Also, as I responded to Daniel, I want to be able to instantiate the default browser - what ever that may be.  How can I get this to work and how can I determine the default browser so that I can open what the user uses?


    For the benefit of others, please mark posts as answered or helpful when they answer or assist you in finding the answer. ___ "We came all this way to explore the Moon, and the most important thing is that we discovered the Earth." - Bill Anders, Apollo 8.

  • viernes, 13 de abril de 2012 15:25
     
     Respondida Tiene código

    You can work around not knowing what browser is installed this way:

    In a standard module:

    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
    'Window Constants
    Public Enum WinMode
        WIN_NORMAL = 1
        WIN_MIN = 2
        WIN_MAX = 3
    End Enum
    Public Sub LaunchOpen(strfile As String, lShowWin As Long)
        Dim lRet As Long
        Dim stRet As String
        lRet = ShellExecute(hWndAccessApp, vbNullString, _
                strfile, vbNullString, vbNullString, lShowWin)
    End Sub


    Bill Mosca
    http://www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    • Marcado como respuesta -suzyQ viernes, 13 de abril de 2012 16:50
    •  
  • viernes, 13 de abril de 2012 16:31
     
     

    Are you sure about FF? I have Chrome as a default browser and Application.FollowHyperlink "http:\\www.ya.ru" opens this site in a new Chrome tab, not IE.

    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru

    I just checked and yes, FF is my default browser.

    For the benefit of others, please mark posts as answered or helpful when they answer or assist you in finding the answer. ___ "We came all this way to explore the Moon, and the most important thing is that we discovered the Earth." - Bill Anders, Apollo 8.

  • viernes, 13 de abril de 2012 16:54
     
     
    Thanks Bill.  It's loading FF for me now; it's doing it faster; and I can do a lot more than 20 or so at a time (not sure how many because I have a tendency to start closing tabs when my window fills up.  I'll have to test it with IE as a default next, but at least I know I can get it to work with something and not freeze after some small threshold.

    For the benefit of others, please mark posts as answered or helpful when they answer or assist you in finding the answer. ___ "We came all this way to explore the Moon, and the most important thing is that we discovered the Earth." - Bill Anders, Apollo 8.

  • viernes, 13 de abril de 2012 16:59
     
     
    Bug? It shouldn't work this way.

    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru

  • viernes, 13 de abril de 2012 17:11
     
     
    Bug? It shouldn't work this way.

    Andrey V Artemyev | Saint-Petersburg, Russia
    Russian blog artemyev.biztoolbox.ru


    not sure, but I know I've been using Firefox for several years now, but when you posted your question I got to thinking that maybe I always clicked on the firefox icon so that's why I was using Firefox, so I checked to see what my default browser is in the registry (and in FF) and it is indeed set up for Firefox.  Application.followhyperlink was indeed opening IE so I don't know what the issue is here, but I used Bill's code above and it works perfectly to open Firefox on my machine.  I still need to test other default browsers, but I think I have a resolution.  Thank you for your help.

    For the benefit of others, please mark posts as answered or helpful when they answer or assist you in finding the answer. ___ "We came all this way to explore the Moon, and the most important thing is that we discovered the Earth." - Bill Anders, Apollo 8.

  • viernes, 13 de abril de 2012 20:26
     
     
    You're welcome, Suzy.

    Bill Mosca
    http://www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals