Link to home
Start Free TrialLog in
Avatar of animallover
animallover

asked on

Open Google Chrome to a specific address from MS Access

Hi all
I have an access database that contains addresses. I need to be able to click on a button that will open the chrome browser, navigate to https://earth.google.com/web/ and, getting the data from the fields in the database, navigate to that address.  Everyone is allowed to use either IE, Chrome, or Firefox as their browser but Google Earth will only work in Chrome so I need it to open Chrome specifically.

Thank you
Avatar of Bill Prew
Bill Prew

Here is a Sub you can use to launch Chrome with a URL.  I included a small Test() Sub to show how it's called.

Option Explicit

Sub Test()
    ' Open a URL with Chrome browser
    LaunchChrome ("www.google.com")
End Sub

Sub LaunchChrome(strUrl As String)
    Dim objReg As Object
    Dim intReturn As Integer
    Dim strChromePath As String
    
    ' Registry constants to locate path to Chrome browser EXE
    Const HKEY_LOCAL_MACHINE = &H80000002
    Const strChromePathKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe"

    ' Get full path for Chrome browser EXE
    Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    intReturn = objReg.GetStringValue(HKEY_LOCAL_MACHINE, strChromePathKey, "", strChromePath)
    Set objReg = Nothing

    ' If Chrome not installed, leave sub (quietly)
    If intReturn <> 0 Then
        Exit Sub
    End If

    ' If no URL passed in just open Chrome, else launch the URL in Chrome
    If strUrl = "" Then
        Call Shell(Quote(strChromePath), vbNormalFocus)
    Else
        Call Shell(Quote(strChromePath) & " -url " & Quote(strUrl), vbNormalFocus)
    End If
End Sub

' Add surrounding double quotes to a string
Function Quote(s)
   Quote = Chr(34) & s & Chr(34)
End Function

Open in new window


»bp
Avatar of animallover

ASKER

That didn't work for me.  I get an error that says "The expression On click you entered as the event property setting produced the following error: A problem occurred while Microsoft Access was communicating with the OLE server or ActiveX Control."
Well, the code I posted didn't have any "on click" in it?

Debug when you get that error, what line is executing ?


»bp
I need to eventually have the user click a button and open google earth with data from the form so I added the LaunchChrome ("www.google.com") to the on click of the button.  There is no debug option, just OK.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

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
I appreciate your help with this.  I haven't had the time to look yet so it will have to wait until Monday.
Okay, understand, happens to me too, let me know how it goes next week.


»bp
Finally able to get back to this and I am so close.  Thank you for the sample DB it helped a lot and I got it working except for using the address on my form to open google earth to that address.  Here is what I have:

Private Sub Map_Click()
Dim strAddress As String
Dim strLink As String

strAddress = Me.PhysicalAddress & " " & Me.PhysicalCity & ", " & Me.PhysicalState
strLink = "https://earth.google.com/web?q=" & strAddress
    LaunchChrome strLink
   
End Sub

It opens up Google Chrome to Google Earth but not to the address.  In the URL the address is concatenated but it doesn't actually go to it.  This is what it looks like (I changed the actual address)
https://earth.google.com/web/?q=1234+W+SOMEWHERE+CRT+TUCSON,+AZ

Any suggestions?
Well, we have answered the original question you asked and that is working now.  The problem you are having now is specific to Google Earth and the URL parameters and search "api".  It may not be possible.  But you are unlikely to get knowledgeable people in this question based on topics.

Best course of action would be to close this question as solved, and then open a new question not about the coding aspect of what you are trying to do, but rather the Google URL format and search syntax.  Find some topics that relate to that URL syntax just entered from a browser, and then just update this code once you get that.


»bp
The rest is part of my original question but I will ask in a separate question. Thank you for your help.