Graham,
Yes I do have an autonumber field, but it works just fine for my needs.
But
I do take your point about flexibility. But also bear in mind that
these
fields are entered using a drop down combo, and are short lists. they
are
not
entered in the traditional typed manner, the idea being least user
input
the
better.
I also take your point about using it outside London. Funny you should
say
that becuase this is exlusively for London (trust me on this...) and
will
never be used elsewhere.
On another note though, I would like the browser to be inside a the
database
and not as an external app. I tried to revert back to my original
browser
setup (using code from another section) but it doesn;t work. How can I
modify
your code call
Application.FollowHyperlink
"
http://maps.google.co.uk/maps?f=q&hl=en&q=" &
sRoute
to make it appear in a WebBrowser control on the form?
or can you tell me why this doesn't work:
Form.frm_Links!LinksMapBrowser.Navigate
"
http://maps.google.co.uk/maps?f=q&hl=en&q=" & sRoute
the error states:
Run_time error 2465 Application-defines or object defined error
regards
Eric
:
Hi Eric
Ah... the difficulties of time zones! You did all this work while I
was
asleep - well done!
I suspect you have on your form a textbox named "Link_Waypoint_Pcode".
Therefore, when you use this expression:
sRoute = sRoute & IIf(iWPCount = 1, "from: ", " to: ") _
& rs![Link_waypoint] & ", " & "London, " &
[Link_Waypoint_Pcode]
(note the absence if the "rs!") you are using the value in that
/textbox/
every time around the loop, and therefore getting the same postcode
repeated
each time.
When you use rs![Link_Waypoint_Pcode] you are referencing the /field/
named
[Link_Waypoint_Pcode] in your recordset, and that changes for each
loop
iteration.
If you will allow me to suggest a few improvements:
1) Link_List_ID sounds suspiciously like an autonumber primary key.
The
problem with this is that you have no control over its value, and
therefore
the order of the waypoints. This means you will run into problems if
you
(a) change the order of the waypoints in a run, or (b) wish to add a
new
waypoint part way through a run. My suggestion was that you use a
non-unique numeric field named "Link_Waypoint_Order" (or similar) and
number
the waypoints /within/ a run in the required order. Then you can
change
the
numbers when you want to change the order or insert a new waypoint.
Note
that you should use this field in the "order by" clause when you open
the
recordset.
2) It may not happen this year, but some time your database might be
used
outside London. I suggest you add a "Link_Waypoint_City" field to
your
table to give you that flexibility. If you wish, you can set its
default
value to "London".
And a question to satisfy my curiosity: I thought the old "N1", "SW4"
postcodes were now obsolete in the UK. Does Google fully understand
them,
and wouldn't you be better to use the new postcode format?
Best of luck to the lads for Saturday. I'm not sure who I want to
win -
it's all too depressing! ;-)
--
Cheers,
Graham Mandeno [Access MVP]
Auckland, New Zealand
Graham,
sorry for the succesive posts, but they are really a timeline to how
I
solved the problem (with your massive input...)
the key line seemed to be:
sRoute = sRoute & IIf(iWPCount = 1, "from: ", " to: ") &
rs![Link_waypoint] & ", " & "London, " & rs![Link_Waypoint_Pcode]
the previous attempt, kept giving me the same postcode for all
addresses,
so
I added an additional 'rs!' before the last field request, as in:
& rs![Link_Waypoint_Pcode]
and this finally solved the entire problem!.
BUT... I don't know why? (I'm a complete novice at recordset stuff),
can
you
explain why and how this made the difference, and maybe how this
whole
code
actually works.
regards
Eric
:
Graham,
I have resolved the problem, but now when I try to incorporate the
postcode;
only the last postcode in the recordset is passed to googlemaps.
the
postcode
field is: [Link_Waypoint_Pcode]
this is the result i get from googlemaps:
from: Liverpool Road, London NW6 to: Abbey Road, London NW6
from this table:
Link_List_ID Run_No Run_Link_ID Link_waypoint Link_Waypoint_Pcode
158 1 1 Liverpool Road N1
159 1 1 Abbey Road NW6
Here is my present code
******************************
Private Sub Command17_Click()
'Assume lngRunNo is either declared elsewhere or passed as an
argument
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sRoute As String
Dim iWPCount As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("Select Link_waypoint,
Link_Waypoint_Pcode
from
tbl_Link_Waypoints where [Run_No]=" & Me.Run_No & " order by
[Link_List_ID];", dbOpenForwardOnly)
Do Until rs.EOF
iWPCount = iWPCount + 1
sRoute = sRoute & IIf(iWPCount = 1, "from: ", " to: ") &
rs![Link_waypoint] & ", " & "London " & [Link_Waypoint_Pcode]
rs.MoveNext
Loop
rs.Close
If iWPCount >= 2 Then
Application.FollowHyperlink
"
http://maps.google.co.uk/maps?f=q&hl=en&q="
& sRoute
Else
MsgBox "Run must have at least two waypoints"
End If
End Sub
************************************
:
Congratulations! It's always good to see a new convert to the
righteous
path of normalisation
I think that you will need another field in your Waypoints table
to
ensure
the waypoints are visited in the correct order. Let's call it
[WP_Seq].
Now your data will look like this:
[Run_No] [WP_Seq] [Link_waypoint]
5 1 Main St
5 2 South St
5 3 Narrow St
5 4 Wide St
5 5 Chester St
Now you need to open a recordset based on a SQL query, and loop
through
the
records for a given [Run_No], appending each [Link_waypoint] to
the
string.
Code will look something like this:
'Assume lngRunNo is either declared elsewhere or passed as an
argument
Dim db as DAO.Database
Dim rs as DAO.Recordset
Dim sRoute as String
Dim iWPCount as Integer
Set db = CurrentDb
Set rs = db.OpenRecordset( _
"Select [Link_waypoint] from tblWaypoints where [Run_No]=" _
& lngRunNo & " order by [WP_Seq];", dbOpenForwardOnly)
Do Until rs.EOF
iWPCount = iWPCount + 1
sRoute = sRoute & IIf( iWPCount=1, "from: ", " to: ") &
rs![Link_waypoint]
rs.MoveNext
Loop
rs.Close
If iWPCount >= 2 then
Application.FollowHyperlink
"
http://maps.google.co.uk/maps?f=q&hl=en&q="
_
& sRoute
Else
MsgBox "Run must have at least two waypoints"
End If
This is "air code" (untested and written on the fly) so sorry if
there
are
any typos or other errors in it. Note that I'm using
"Application.FollowHyperlink" instead of shelling iexplore.
Easier
and
more
reliable.
--
Good Luck
Graham Mandeno [Access MVP]
Auckland, New Zealand
PS: Grudging congrats to your rugby players ;-)
message
previously, I was able to do this by having seperate field
names;
for
example:
stAppName = "C:\Program Files\Internet Explorer\iexplore.exe
http://maps.google.co.uk/maps?f=q&hl=en&q= " & "from: " &
Link_Waypoint_1
+
", London" & (" to: " + Link_Waypoint_2 + ", London") & (" to:
" +