Open Ms Access from Google Earth

This is a function - very similar to a function in VBA or any other language. It first sets a lookat point and then simply looks at that view. You need to review the Google API to understand it better.

The function also sets two event listeners.

Code:
window.google.earth.addEventListener(ge.getWindow(), 'mousedown',stopFlight);

This is a window wide (whole webbrowser) event listener, it is listening for the mousedown event and when that happens it calls the "stopFlight" function.

Code:
google.earth.addEventListener(ge.getView(), "viewchangeend", pointreached);

similarly this is a google earth wide listener which listens for a special event that GE throws and that is "viewchanged" this event is thrown when the GE reaches the viewpoint. Then it calls the function "pointreached". This is the event listener which is the key to making your flight.

The functions then remove the eventlisteners WHICH IS IMPORTANT and then fires a navigation change. Did you put window.location into google search and read??? This is going to try and navigate to window.location = ('03'); a page named "03" which of course does not exist. You are going to CANCEL the navigation see in the URL what page it is (in this case 03) and know that the next point needs to be given to GE.

Whilst it is all a VBA/Access project I really must say again that the Javascript stuff is not really for this forum and I only learnt enough to be dangerous with GE.

Hi Darbid,
Thanks again.

I did some research (using google search engine) before sending my last post on Windows.Location (it's just that am a newbie in JavaScript programming).

I understand your explanation on navigating to a fake page [windows.location(3)] but i don't know if there is a function i need to refer to in your previous post that explains what you mean by 'case 03'.

I have been trying to decode your last post thats why it has taken me this long to reply.

Am i omitting any function that i should add.
Thanks agn
 
JT Kent;1013060 I understand your explanation on navigating to a fake page [windows.location(3) said:
but i don't know if there is a function i need to refer to in your previous post that explains what you mean by 'case 03'.
Great.

So when GE tries to navigate your webbrowser control catches it in the BeforeNavigate2. That event has the URL in it. Look at this URL which is a string - it will be the full path of where it wants to navigate to. But you only need the last bit because the rest of the path is always the same. So before the select case you need to set up a function to get rid of the rest of the string from the URL.

I would suggest you post an example MDB if you are that stage.
 
Hi Darbid,
I can't attach the sample database cos it's too large.
i however can explain the structure of the database and attach the code

The table name is tblplaces and the form is Map Browser.
My code navigates through the recordsets similar to how you told me to do it.

Private Sub GE_next_flight_point_Click()
On Error GoTo Err_GE_next_flight_point

Dim po_Lat As Single
Dim po_Long As Single
Dim po_Alt As Single
Dim ge_Speed As String

Dim conID As String

Dim db As Database, GE_flight_rs As DAO.Recordset
Dim GE_flight_ok_move_next As Boolean

GE_flight_ok_move_next = True
Set db = CurrentDb

Set GE_flight_rs = db.OpenRecordset("tblplaces", dbOpenDynaset)
GE_flight_rs.MoveFirst

'Debug.Print "*********************GE_next_flight_point****************"

'1 appears to take about 1.5 sec
'thus 0.5 will take about 3 sec
'thus 0.25 will take about 6 seconds

'ge_Speed = str_GE_FLY_SPEED

ge_Speed = 1
ge_Speed = Replace(ge_Speed, ",", ".")

po_Alt = 1000

If Not GE_flight_rs.EOF Then

'two important goto points
po_Lat = GE_flight_rs!latitude
po_Long = GE_flight_rs!longitude

'conID = Nz(GE_flight_rs![main_contract_ID])
'Debug.Print "*************** " & Nz(GE_flight_rs![main_licensee_name])
'Debug.Print "*************** " & Nz(GE_flight_rs![main_contract_ID])

Else
GE_flight_rs.Close
Set GE_flight_rs = Nothing
Exit Sub
End If

If GE_flight_ok_move_next Then
GE_flight_rs.MoveNext
End If

'Debug.Print "****po_Lat***** " & po_Lat
'Debug.Print "****po_Long**** " & po_Long
'Debug.Print "****ge_Speed**** " & ge_Speed
'Debug.Print "****po_Alt**** " & po_Alt

Call mydoc.parentWindow.execScript("pointtour('" & po_Lat & "','" & po_Long & "','" & po_Alt & "'," & _
ge_Speed & ")", "Jscript")


Exit_GE_next_flight_point:
Exit Sub

Err_GE_next_flight_point:
MsgBox Err.Description
Resume Exit_GE_next_flight_point
End Sub



Kindly help me with the BeforeNavigation code as i dont know how to handle this aspect.

Thanks a lot.
 
The before navigate has the URL it wants to navigate to.

The way I always do it is the first 2 numbers of my page i send the browser to is a code so I know what I want to do. In this case just "03".

If for example I wanted information I would make it go to the page "05myinformation"

Then I would do a Case "05" then get the rest of the information from the string.

Code:
Dim strfrombrowser As String 

Cancel = True ' always need this
Debug.Print URL

'get just my information
strfrombrowser = Right(URL, (Len(URL) - InStrRev(URL, "/")))

'this is just the code 
Debug.Print "Before Navigate left 2 URL - " & Left(strfrombrowser, 2)


Select Case Left(strfrombrowser, 2)
Case "03"
        'do what you want.
end select
 
Last edited:
Hi Darbid,
Thanks agn for all your help.

I have finally been able to attach the database file.
As i said earlier it has a table called tblplaces with the Longitude, Latitude and a constant Altitude for the Locations in the tour.

I attached the code that loops through the recordsets of places.
I would like you to demonstrate the code for the BeforeNavigation Event in the attached database for a better understanding of your explanation.

Thank you.
 

Attachments

Hi Darbid,
Thanks agn for all your help.

I have finally been able to attach the database file.
As i said earlier it has a table called tblplaces with the Longitude, Latitude and a constant Altitude for the Locations in the tour.

I attached the code that loops through the recordsets of places.
I would like you to demonstrate the code for the BeforeNavigation Event in the attached database for a better understanding of your explanation.

Thank you.
 

Attachments

Hey here you go, but I really like people that look like they "had a go" themselves first. The main reason is that you learn.

The only navigation you needed you had changed. I changed it back to a three.
 

Attachments

Hey here you go, but I really like people that look like they "had a go" themselves first. The main reason is that you learn.

Hi Darbid,
Firstly let me say a big thank you for all your help thus far.

On your comment, i did "have a go" but at a point, i was beginning to feel that you might begin to start running out of patience with me cos i still was not comfortable with your explanation.

I have seen the sample database i sent to you but you mentioned via a message box that i have to loop to the next recordset in case03.

The issue is that how will i loop to the next Recordset (in the BeforeNavigation function) if the recordset was declared in a Private Function and the loop is supposed to occur in a different function?

For instance, if i type

GE_flight_rs.MoveNext

Call mydoc.parentWindow.execScript("pointtour('" & po_Lat & "','" & po_Long & "','" & po_Alt & "'," & _
ge_Speed & ")", "Jscript").

It means i am moving to the next Recordset and calling the function "point tour" when the Recordset was declared in a different function.

So as it is, i still have issues the next step i.e looping to the next Recordset.
Please, remember that i am a newbie to VBA/JavaScript and i have been learning a lot from you.
Thanks so much.
 
your code is different you need to follow exactly what I wrote here

http://www.access-programmers.co.uk/forums/showpost.php?p=1012145&postcount=37

You need to declare FORM variables - practically that means at the top of the form and not in a sub routine.

In Case 03 you then call the function GE_next_flight_point

Other than the field names GE_next_flight_point can be cut and copied. Note in GE_next_flight_point there is NO SQL, NO DB, NO RS - this is because it was already set.
 
Hi Buddy,
Thanks for your time and support.

Though i have declared the Recordset and other variables in the function as Global variables and called the on_click function in Case03, the tour is still not going to the other locations except the first one.

Well, i guess i'll continue to try to crack that problem. I am grateful for leading me along the right path. I would not have gotten this far with the database on my own.

To other issues, i remember you mentioned that i cannot open a local file on my computer via a hyperlink in the pop-up dialog that opens when i select a location from GE.

But is it possible to use a hyperlink (in the pop-up that appears when a location is selected in GE) to open a form/a small dialog box?

I would really like to know if this is possible.

Thanks again.
 
Hi Buddy,
Thanks for your time and support.

Though i have declared the Recordset and other variables in the function as Global variables and called the on_click function in Case03, the tour is still not going to the other locations except the first one.

When you click a button you build your SQL and set your RS. That is all the button click does. At the end of this routine call my function to get it started.

Then use my function exactly as I have except change the field names to suit your names.

When GE says it has reched the destination and send a code 03 then you call my function only.

You have to spit it up like that so that you can come back and move to the next record.


To other issues, i remember you mentioned that i cannot open a local file on my computer via a hyperlink in the pop-up dialog that opens when i select a location from GE.

But is it possible to use a hyperlink (in the pop-up that appears when a location is selected in GE) to open a form/a small dialog box?

I would really like to know if this is possible.

Thanks again.
No I said you cannot open a KML file with GE from the webbrowser. A hyperlink can open any file anywhere. Just like the attachments in this forum.

Once again you need to use the Beforeupdate method again.

Lets say you add a point to GE - you can add an ID (your primary key from your databse) to the point in GE. Then when a user clicks on the point you nagivate to that ID. Your before navigate picks it up and send the ID which is actually a primary key to a routine which gets that record and you show a small form with the result.

I use this a lot because you must remember that Google is a massive vacuum cleaner storing all your information.

Also GE can never have the same ID given twice in a session so you need to deal with that as well.

Let get you looping the world with your choosen record set first.
 
Hi Darbid,
Hope you are good. I have a few questions/issues i need to clarify.

When you click a button you build your SQL and set your RS. That is all the button click does.

This includes setting the boolean variable "GE_flight_ok_move_next" to true, setting the database object to current db, opening the Recordset and moving to the first record in the Recordset.

These are the assignments that are triggered when the user clicks on the button. I hope am on the right track.

At the end of this routine call my function to get it started.

1.Firstly, what do you mean by routine? Do you imply after the button click event (the function that declares the Recordsets and moves to the first recordset)?

2.Which function exactly are you refering to? Is it the JavaScript "point tour" function or the function you sent that navigates through the Recordsets to the next location?

3.Finally on this issue, if i don't call the function (whichever one you are refering to based on question 2) from the button click event, where do i call it from?

Then use my function exactly as I have except change the field names to suit your names.

Are you implying that i have to call "your function" (whichever one you are refering to) again? if so where? I obviously know i have to change the field names which i have done accordingly.

When GE says it has reched the destination and send a code 03 then you call my function only.

When i know the function you are refering to, i will know exactly which function to call.

No I said you cannot open a KML file with GE from the webbrowser. A hyperlink can open any file anywhere. Just like the attachments in this forum.

Maybe you did not get my explanation. I don't intend to open a KML File from the hyperlink. Actually i intend to open a parameter-based Report residing in the same database from the hyperlink. Is this possible?


Once again you need to use the Beforeupdate method again.

Lets say you add a point to GE - you can add an ID (your primary key from your databse) to the point in GE. Then when a user clicks on the point you nagivate to that ID. Your before navigate picks it up and send the ID which is actually a primary key to a routine which gets that record and you show a small form with the result.

I use this a lot because you must remember that Google is a massive vacuum cleaner storing all your information.

Also GE can never have the same ID given twice in a session so you need to deal with that as well.

Let get you looping the world with your choosen record set first.

The BeforeUpdate Method you refered to is based on which control (textbox,combobox)?

Can you explain how the routine you refered to that retrieves the specified record from the database.

Actually, this aspect is just as important as the tour aspect.

Thanks.
 
One thing at a time.

Your flight.

Here is the setting of my recordset. If you do not see a variable declared in these routines that is because they are form variables declared at the top of your form.

This is my button to set up the record set

Code:
Private Sub btn_fly_contracts_Click()
On Error GoTo Err_btn_fly_contracts_Click

Dim strGE_SQL As String
Dim sql_temp As String

'I am using ADODB with a connection - you need to change this to your own way of getting your Recordset
Set GE_flight_rs = New ADODB.Recordset
Call OpenConnection
Set GE_flight_rs.ActiveConnection = gcnn


'here is my SQL
strGE_SQL = "SELECT ;"

'here I open the record set
GE_flight_rs.Open strGE_SQL, gcnn, adOpenStatic, adLockOptimistic

If Not GE_flight_rs.RecordCount > 0 Then
    GoTo Exit_btn_fly_contracts_Click
End If

'go to the first record
GE_flight_rs.MoveFirst

GE_flight_ok_move_next = True

'calling my function for the first time to get the flight underway
Call GE_next_flight_point

Exit_btn_fly_contracts_Click:
    Exit Sub

Err_btn_fly_contracts_Click:
    MsgBox Err.Description
    Resume Exit_btn_fly_contracts_Click


End Sub
You will note that it calls "Call GE_next_flight_point"

you have this code.

Call GE_next_flight_point sends the information to GE

GE flys to the point

When GE flys to the point and arrives it navigates to page "03"

You see this in the Before Update and call "Call GE_next_flight_point"

and so it continues.
 
Hi Darbid,
Please note that my assumption is that we have 1 command button that controls the tour and no separate ones to declare Recordsets.

One thing at a time.

Your flight.

Here is the setting of my recordset. If you do not see a variable declared in these routines that is because they are form variables declared at the top of your form.

This is my button to set up the record set

Am a little confused about the button issue. Are there 2 buttons on your form? The first to set up the Recordsets and the other to handle the navigation/tour.

I thought i was supposed to have 1 button which would set up the recordset and then Call GE_next_flight_point at the same time.

Am i mixing things up?

Code:
Private Sub btn_fly_contracts_Click()
On Error GoTo Err_btn_fly_contracts_Click

Dim strGE_SQL As String
Dim sql_temp As String

'I am using ADODB with a connection - you need to change this to your own way of getting your Recordset
Set GE_flight_rs = New ADODB.Recordset
Call OpenConnection
Set GE_flight_rs.ActiveConnection = gcnn


'here is my SQL
strGE_SQL = "SELECT ;"

'here I open the record set
GE_flight_rs.Open strGE_SQL, gcnn, adOpenStatic, adLockOptimistic

If Not GE_flight_rs.RecordCount > 0 Then
    GoTo Exit_btn_fly_contracts_Click
End If

'go to the first record
GE_flight_rs.MoveFirst

GE_flight_ok_move_next = True

'calling my function for the first time to get the flight underway
Call GE_next_flight_point

Exit_btn_fly_contracts_Click:
    Exit Sub

Err_btn_fly_contracts_Click:
    MsgBox Err.Description
    Resume Exit_btn_fly_contracts_Click


End Sub
You will note that it calls "Call GE_next_flight_point"

you have this code.

Call GE_next_flight_point sends the information to GE

GE flys to the point

When GE flys to the point and arrives it navigates to page "03"

You see this in the Before Update and call "Call GE_next_flight_point"

and so it continues.

Below is the code for GE_next_flight_point

Code:
Private Sub GE_next_flight_point_Click()
On Error GoTo Err_GE_next_flight_point

Dim po_Lat As Single
Dim po_Long As Single
Dim po_Alt As Single
Dim ge_Speed As String

Dim conID As String

'This is my Recordset Declaration which i have moved to btn_fly_contracts_Click as you advised in your last post

[COLOR="Red"]Dim db As Database, GE_flight_rs As DAO.Recordset
Dim GE_flight_ok_move_next As Boolean

Set db = CurrentDb
Set GE_flight_rs = db.OpenRecordset("tblplaces", dbOpenDynaset)
[/COLOR]


GE_flight_ok_move_next = True
GE_flight_rs.MoveFirst

'Debug.Print "*********************GE_next_flight_point****************"

'1 appears to take about 1.5 sec
'thus 0.5 will take about 3 sec
'thus 0.25 will take about 6 seconds

'ge_Speed = str_GE_FLY_SPEED

ge_Speed = 1
ge_Speed = Replace(ge_Speed, ",", ".")

po_Alt = 1000

If Not GE_flight_rs.EOF Then
   
   'two important goto points
    po_Lat = GE_flight_rs!latitude
    po_Long = GE_flight_rs!longitude
    
    'conID = Nz(GE_flight_rs![main_contract_ID])
    'Debug.Print "*************** " & Nz(GE_flight_rs![main_licensee_name])
    'Debug.Print "*************** " & Nz(GE_flight_rs![main_contract_ID])
 
Else
    GE_flight_rs.Close
    Set GE_flight_rs = Nothing
    Exit Sub
End If

If GE_flight_ok_move_next Then
        GE_flight_rs.MoveNext
    End If

'Debug.Print "****po_Lat***** " & po_Lat
'Debug.Print "****po_Long**** " & po_Long
'Debug.Print "****ge_Speed**** " & ge_Speed
'Debug.Print "****po_Alt**** " & po_Alt

Call mydoc.parentWindow.execScript("pointtour('" & po_Lat & "','" & po_Long & "','" & po_Alt & "'," & _
                         ge_Speed & ")", "Jscript")


Exit_GE_next_flight_point:
    Exit Sub

Err_GE_next_flight_point:
    MsgBox Err.Description
    Resume Exit_GE_next_flight_point
End Sub

You will notice that the following lines of code appear in GE_next_flight_point and btn_fly_contracts_Click.

Code:
GE_flight_ok_move_next = True
GE_flight_rs.MoveFirst

I suspect that something is wrong. if i remove these lines of code from GE_next_flight_point, the application moves only to the first location and if i leave the lines of code, i get the same result.

In summary, i can't still tour my Locations. What can i do next?

I appreciate your patience.
Thanks
 
Give me your mdb but in 2003 format I do not have access to 2007 at the moement. And make sure it has in it what you have above.

Hi Darbid,
Apologies for replying this late. I haven't had access to the internet all day.

I have attached the database in the format you requested for.
Thanks again.
 

Attachments

I would officially like to introduce you to the ctrl-c / ctrl-v club. You only needed to copy GE_next_flight_point

What is all that extra guff in "Public Sub GE_next_flight_point" :)

Couple of things SPEED and Altitude - GE will move on to the next point before it downloads a clear image of where it currently is. Thus you need to slow it down or make a higher altitude so that there is not as much information that needs to be given to the GE.


Make sure you set to nothing "Dim mydoc As MSHTML.HTMLDocument" before you leave that Access form otherwise you might cause problems for the GE control. (I am not an expert but it is good practice to do this)

You also have other declarations in the form which I do not think you need there. The lat long etc do you really need those declared at form level?
 

Attachments

I would officially like to introduce you to the ctrl-c / ctrl-v club. You only needed to copy GE_next_flight_point

What is all that extra guff in "Public Sub GE_next_flight_point" :)

Couple of things SPEED and Altitude - GE will move on to the next point before it downloads a clear image of where it currently is. Thus you need to slow it down or make a higher altitude so that there is not as much information that needs to be given to the GE.


Make sure you set to nothing "Dim mydoc As MSHTML.HTMLDocument" before you leave that Access form otherwise you might cause problems for the GE control. (I am not an expert but it is good practice to do this)

You also have other declarations in the form which I do not think you need there. The lat long etc do you really need those declared at form level?

Thanks a lot Darbid,
I knew something was wrong with the GE_next_flight_point function but am suprised i was not able to crack it because i removed those duplicated lines of code i quoted in my last mail but still had issues.

A valid point you made regarding Speed and Altitude. I have already noted that and dealt with it decisively. Now i can tour the world with my application thanks to you.

Now to the other issue i was informing you about.
On the GE instance from my Ms Access Application, i added a placemark that if clicked upon opens a dialog window with the Placemark's details such as Longitude, Latitude e.t.c.

I want to create a hyperlink on that dialog that if clicked upon opens a Parameter-based Report residing within the same database. Is this really possible?

I knew you were explaining a concept on using IDs to retrieve data from tables but sincerely i did not understand and you did not really go deep with the explanation.

Now would be a real good time.
Thanks again buddy. I owe you one.
 
look at this post

http://www.access-programmers.co.uk/forums/showpost.php?p=1008218&postcount=7

When creating this point it creates a special action for GE - when you click on the pin it opens a little dialog in GE - you can put information on it. You use HTML format in this dialog. If you do not want all your information on this then create a hyper link on it. The concept is then the same - hyperlink tries to navigate to a page - you stop it and take the information that you need.

As I am sure I have already said my links usually look like this

02;45894833;some message

or

linkID;recordID;message



Then in the beforenavigate you look for the linkID to get it in the right place in the Select - then use the SPLIT function to get out each string in the ";" then call a function to show a dialog in your access database by passing it your recordID or message.
 
look at this post

http://www.access-programmers.co.uk/forums/showpost.php?p=1008218&postcount=7

When creating this point it creates a special action for GE - when you click on the pin it opens a little dialog in GE - you can put information on it. You use HTML format in this dialog. If you do not want all your information on this then create a hyper link on it. The concept is then the same - hyperlink tries to navigate to a page - you stop it and take the information that you need.

As I am sure I have already said my links usually look like this

02;45894833;some message

or

linkID;recordID;message



Then in the beforenavigate you look for the linkID to get it in the right place in the Select - then use the SPLIT function to get out each string in the ";" then call a function to show a dialog in your access database by passing it your recordID or message.

Hi Darbid,
I understand the approach with respect to initiating a navigation, then cancelling it and then instigating an action in the Case Statement.

This means i will have to write a JavaScript Function (that will perform a task) and call that function.

May be i should explain the task at hand and then you would guide me on how it could be done.

I have a placemark on my GE instance. On clicking this placemark, a dialog/description window opens with a hyperlink in it. On clicking this hyperlink, i want a parameter-based report (within the same database) to open.

I can specify the attributes of this report via the parameters (very similar to entering parameters to display query results in Ms Access) and the result is displayed in the form of a report.

As i said earlier, do i need to write a JavaScript function of my own to do this and call it from VBA later on?

I need some guidance as to getting this done.
 

Users who are viewing this thread

Back
Top Bottom