Google maps from form

  • Thread starter Jean-Paul De Winter
  • Start date
J

Jean-Paul De Winter

Hi,
I have a form with a streetname and a city name...
It would be great to have a pushbutton that, when clicked, opens google maps
and automatically graps the street and city name form the form to immediatly
go to the correct map.

Hope I explained it clear enough....

Tanks
 
J

Jean-Paul

Thanks for your kind help...
But... This is what I did

I added everything between Dunctio and End Function in my main form
I created a pushbutton on my form and wrote:

Private Sub Knop89_Click()
OpenMap Me.Adres, Me.Gemeente, Me.Postbus, Me.land
End Sub

This returns a complation error:
Sub or function is not defined

I must have done something wrong

Also, you wrote:
OpenMap Me.txtAddress, Me.txtCity, Me.txtState, Me.txtZip, Me.txtCountry

Here in Belgium we don't have Statenames, so I wrote:
OpenMap Me.txtAddress, Me.txtCity, Me.txtZip, Me.txtCountry

Thanks
JP
 
P

Piet Linden

Also, you wrote:

OpenMap Me.txtAddress, Me.txtCity, Me.txtState, Me.txtZip, Me.txtCountry

.... it's a function, so you have to use
OpenMap (Me.txtAddress, Me.txtCity, Me.txtState, Me.txtZip,
Me.txtCountry)

the above syntax (without parentheses) is for subroutines.
 
J

Jean-Paul

Piet said:
... it's a function, so you have to use
OpenMap (Me.txtAddress, Me.txtCity, Me.txtState, Me.txtZip,
Me.txtCountry)

the above syntax (without parentheses) is for subroutines.

When I write:
Private Sub Knop89_Click()
OpenMap (Me.Adres, Me.Gemeente, Me.Postbus, Me.land)
End Sub

It returns a "syntax error"
Also, entering ( colours the text red

SO... problem not solved... sorry
 
J

Jean-Paul

This is what I wrote:

Function OpenMap(Address, City, State, Zip, Country)
Dim strAddress As String
strAddress = Nz(Adres)
strAddress = strAddress & IIf(strAddress = "", "", ", ") & Nz(Gemeente)
strAddress = strAddress & IIf(strAddress = "", "", ", ") & Nz(Postbus)
strAddress = strAddress & IIf(strAddress = "", "", ", ") & Nz(land)


If strAddress = "" Then
MsgBox "There is no address to map."
Else
Application.FollowHyperlink
"http://maps.live.com/default.aspx?where1=" & strAddress
End If
End Function

I think I indeed changed things like it should....
Still get same errormessage.

JP
Jean-Paul,

Did you really copy the function from Boyd? You will need to correct the
function string.

Jean-Paul said:
Also, you wrote:
[quoted text clipped - 23 lines]
the above syntax (without parentheses) is for subroutines.
When I write:
Private Sub Knop89_Click()
OpenMap (Me.Adres, Me.Gemeente, Me.Postbus, Me.land)
End Sub

It returns a "syntax error"
Also, entering ( colours the text red

SO... problem not solved... sorry
 
D

Douglas J. Steele

Typing code into newsgroup posts is often problematic, since there are
restrictions on how wide a line of text can be before it wraps.

Hopefully you realize that

Application.FollowHyperlink

should be on the same line as

"http://maps.live.com/default.aspx?where1=" & strAddress

or else there should be a line continuation character (a space followed by
an underscore character) following Application.FollowHyperlink

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Jean-Paul said:
This is what I wrote:

Function OpenMap(Address, City, State, Zip, Country)
Dim strAddress As String
strAddress = Nz(Adres)
strAddress = strAddress & IIf(strAddress = "", "", ", ") &
Nz(Gemeente)
strAddress = strAddress & IIf(strAddress = "", "", ", ") & Nz(Postbus)
strAddress = strAddress & IIf(strAddress = "", "", ", ") & Nz(land)


If strAddress = "" Then
MsgBox "There is no address to map."
Else
Application.FollowHyperlink
"http://maps.live.com/default.aspx?where1=" & strAddress
End If
End Function

I think I indeed changed things like it should....
Still get same errormessage.

JP
Jean-Paul,

Did you really copy the function from Boyd? You will need to correct the
function string.

Jean-Paul said:
Also, you wrote:
[quoted text clipped - 23 lines]
the above syntax (without parentheses) is for subroutines.
When I write:
Private Sub Knop89_Click()
OpenMap (Me.Adres, Me.Gemeente, Me.Postbus, Me.land)
End Sub

It returns a "syntax error"
Also, entering ( colours the text red

SO... problem not solved... sorry
 
J

Jean-Paul

The errormessage is

The argument is not optional (free translation from my Dutch access version)
at this line
in the
OpenMap Me.Adres, Me.Gemeente, Me.Postbus, Me.land

of the property of a pushbutton:

Private Sub Knop89_Click()
OpenMap (Me.Adres, Me.Gemeente, Me.Postbus, Me.land)
End Sub

Jean-Paul said:
This is what I wrote:

Function OpenMap(Address, City, State, Zip, Country)
Dim strAddress As String
strAddress = Nz(Adres)
strAddress = strAddress & IIf(strAddress = "", "", ", ") & Nz(Gemeente)
strAddress = strAddress & IIf(strAddress = "", "", ", ") & Nz(Postbus)
strAddress = strAddress & IIf(strAddress = "", "", ", ") & Nz(land)


If strAddress = "" Then
MsgBox "There is no address to map."
Else
Application.FollowHyperlink
"http://maps.live.com/default.aspx?where1=" & strAddress
End If
End Function

I think I indeed changed things like it should....
Still get same errormessage.

JP
Jean-Paul,

Did you really copy the function from Boyd? You will need to correct the
function string.

Jean-Paul said:
Also, you wrote:
[quoted text clipped - 23 lines]
the above syntax (without parentheses) is for subroutines.
When I write:
Private Sub Knop89_Click()
OpenMap (Me.Adres, Me.Gemeente, Me.Postbus, Me.land)
End Sub

It returns a "syntax error"
Also, entering ( colours the text red

SO... problem not solved... sorry
 
D

Douglas J. Steele

You're showing two different statements there:

OpenMap Me.Adres, Me.Gemeente, Me.Postbus, Me.land

And

OpenMap (Me.Adres, Me.Gemeente, Me.Postbus, Me.land)

The parentheses matter. You need either to leave out the parentheses, or use
the Call keyword. In other words, both of these should work:

OpenMap Me.Adres, Me.Gemeente, Me.Postbus, Me.land

And

Call OpenMap (Me.Adres, Me.Gemeente, Me.Postbus, Me.land)

This will not work:

OpenMap (Me.Adres, Me.Gemeente, Me.Postbus, Me.land)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Jean-Paul said:
The errormessage is

The argument is not optional (free translation from my Dutch access
version)
at this line
in the
OpenMap Me.Adres, Me.Gemeente, Me.Postbus, Me.land

of the property of a pushbutton:

Private Sub Knop89_Click()
OpenMap (Me.Adres, Me.Gemeente, Me.Postbus, Me.land)
End Sub

Jean-Paul said:
This is what I wrote:

Function OpenMap(Address, City, State, Zip, Country)
Dim strAddress As String
strAddress = Nz(Adres)
strAddress = strAddress & IIf(strAddress = "", "", ", ") &
Nz(Gemeente)
strAddress = strAddress & IIf(strAddress = "", "", ", ") &
Nz(Postbus)
strAddress = strAddress & IIf(strAddress = "", "", ", ") & Nz(land)


If strAddress = "" Then
MsgBox "There is no address to map."
Else
Application.FollowHyperlink
"http://maps.live.com/default.aspx?where1=" & strAddress
End If
End Function

I think I indeed changed things like it should....
Still get same errormessage.

JP
Jean-Paul,

Did you really copy the function from Boyd? You will need to correct the
function string.

Jean-Paul wrote:
Also, you wrote:
[quoted text clipped - 23 lines]
the above syntax (without parentheses) is for subroutines.
When I write:
Private Sub Knop89_Click()
OpenMap (Me.Adres, Me.Gemeente, Me.Postbus, Me.land)
End Sub

It returns a "syntax error"
Also, entering ( colours the text red

SO... problem not solved... sorry
 
J

Jean-Paul

Great, it ssems to work now.... but..

I live in België

Notice the 2 points above the e

Whan I run the code, Google looks for belgi en ommits the ë, so doesn't
find anything.
When I add ë to the searched address... the location is shown on the map.

Also...

Can I add some code to check if there is an internet connection or not?

Thank you for your kind help
 
D

Douglas J. Steele

The implication is that whatever you're passing as the country name must
include the proper accents.

Randy Birch shows one way to determine whether there's an internet
connection at
http://vbnet.mvps.org/code/internet/internetcheckconnection.htm

Obligatory warning: Randy's site is aimed at Visual Basic programmers. There
are some significant differences between the controls available for forms in
VB and in Access, so that some of his sample code will not port directly to
Access without some tweaking. Looking at this particular sample, though, I
see no issues. (other than the fact that he made a typo in the first line of
code: there should only be one keyword Private)
 
J

Jean-Paul

Again... and this is strange, when I change all country names from
België to Belgie it works just perfect
When the country-name is België the code ommits the last ë en searches
for Belgi... without finding anything.

Strange... would be great to be able to solve the problem, otherwise I
have to write my country-name incorrectly

JP
 
D

Douglas J. Steele

Use the Replace function to change the ë to e when you pass it to Google.

In that way, you can still store it like you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top