georeference.org
Subscribe to this thread
Home - Scripting / All posts - VB6 and Access click events in MapControl
kgf63 post(s)
#23-Jun-09 06:26

Hi All

I am having trouble getting events to fire in an access form. I can change the mousemode but cant seem to get an event to register.

Private Sub Command8_Click()

Set M = ActiveXCtlfrmAllPoints.Object

M.MouseMode = ControlMouseModeGenericPoint

End Sub

The above works to change the mouse mode but i cant seem to get the event to work. I would like to be able to capture the X,Y of the click. I am not sure which event is triggered from a point click, but nether seems to work with the below vb.

Private Sub ActiveXCtlfrmAllPoints_BeginTrack(ByVal pArgs As Object)

MsgBox "begin track"

End Sub

Private Sub ActiveXCtlfrmAllPoints_EndTrack(ByVal pArgs As Object)

MsgBox "end track"

End Sub

Forest
445 post(s)
#23-Jun-09 16:37

I think I need to whinge and bitch too. I can get an access form with a map up and running but all it does is show the map document at extents. The source of my issues is that when you want to do something simple, you have to face the complexity of the Manifold object model. All I can do is show a map zoomed to extents rather than displayed already zoomed to the area of interest. I had a go at working through the manifold object maze to zoom in to the area of interest. This is general algorythm. An area of interest is the same as a View, which is defined by a centre point and scale (similar to kgf's issue). A point object contains coordinates in manifolds internal format and you need to used the coordinate system object to convert these to real world coordinates. The coordinate system needs projection system parameters or a predefined projection ID so off one goes looking the an object that can supply that information. I am sick of looking at error messages from unhappy objects. Surely there has to be a simple way to zoom and pan to an area of interest. I would really appreciate a road map or object diagram just for this task.

kgf63 post(s)
#01-Jul-09 10:48

To Zoom in to an object in an access 2000 form i use the following.

Dim M As New ComponentControl

Set M = ActiveXCtl.Object

Set comps = M.Document.ComponentSet

Set dwg = comps("XYPoint")

Set zoom = comps("PointExtent")

Set os = dwg.ObjectSet

Set extent = zoom.ObjectSet

' remove previous objects in sets

os.RemoveAll

extent.RemoveAll

Set P = M.Application.NewPoint

Set Px = M.Application.NewPoint

P.X = Me.Easting ' from easting txt box on access form

P.Y = Me.Northing ' from northing txt box on access form

Set g = M.Application.NewGeom(GeomPoint, P)

os.Add (g)

' this adds 500 m +/- to x,y point so that the map zooms into the point centred within a 1km view

Px.X = Me.Easting + 500

Px.Y = Me.Northing + 500

Set gx = M.Application.NewGeom(GeomPoint, Px)

extent.Add (gx)

P.X = Me.Easting - 500

P.Y = Me.Northing - 500

Set gx = M.Application.NewGeom(GeomPoint, P)

extent.Add (gx)

M.Refresh

M.ZoomTo (zoom)

Set M = Nothing

Set doc = Nothing

Set comps = Nothing

Set dwg = Nothing

Set zoom = Nothing

Set os = Nothing

Set extent = Nothing

I also use a drawing in the project called Scope which sets the bounds i want. To set the map to this rather than full extents i use

..

Set mapscope = comps("Scope")

...

M.ZoomTo (mapscope)

I can get the map to zoom to objects in a database (in easting and northings fields) but hoping someone can shed some light on click events in access so i can add the coords from a click to the database.

Forest
445 post(s)
#01-Jul-09 17:33

Thanks kgf,

I got your code to work in ms-access 2003. For anyone also trying this, what I did was put a manifold map object on an ms-access form and also a command button. I pasted the above code into the OnClick event of the command button. The above code needs to be adjusted a little to suit the map document that is loaded in the manifold map control.

Before you do that, you need to ensure that in the properties for the map control, on the Other tab, you have set the document path to the manifold map file you want to view eg something like "C:\_Forest\WorkOrders.map". You will also need to set the component name to the name of the map that you would like to view eg. "WorkOrders". I think that you can only view drawings and maps, not layouts. Give your MapControl a name that you can refer to in code eg. "CaneFieldsMap".

The above code requires that a drawing called XYPoint and another drawing called PointExtent exist in your map document, so use Manifold to create them if they do not exist. The data in these drawings is deleted by the above code, so these drawing should be empty.

Adjusting the code. I always use Option Explicit in ms-access so I had declare all of the variables in the above code.

Dim comps, dwg, os, extent, p, Px, g, gx, zoom, doc

Dim M As New ComponentControl

Next M has to be linked to the Manifold Map Control on your form.

Set M = Me.CaneFieldMap.Object

The rest of the code should work fine. Note that the code puts a point in one drawing on the map and creates a box in another drawing and then zooms to the box. If you don't need the point, then you can simplify the code a fair bit.

Cheers

Forest

kgf63 post(s)
#02-Jul-09 12:19

I should have explained myself better with the previous code. Thanks Forest.

I am using the manifold object in an access database that records points. I have the database linked to the Map file using X and Y fields, these points show up on the Map Control i have on the access form.

But to identify which point the database record refers to i have the following code on the oncurrent event of the form.

As i move between records it puts a temporary point on the Map control to identify the current records location.

So i have the linked drawing showing all the database points and the drawing XYPoint showing the current database record via code. In some ways the current record is linked twice to the map. But it seems to work and quickly enough to go back and forward through records with a point moving all over the map.

Set dwg = comps("XYPoint") ' empty drawing the the Map project but formatted to what i need

Set scope = comps("MapScope") ' drawing in the Map with the bounds i would like to zoom to

Set os = dwg.ObjectSet

os.RemoveAll

Set P = M.Application.NewPoint

P.X = Me.Easting ' form controls with the database x and y in them

P.Y = Me.Northing

Set g = M.Application.NewGeom(GeomPoint, P)

os.Add (g)

M.Refresh

M.ZoomTo (scope) ' zooms to drawing MapScope

I also have similar code on the easting and northing 'afterupdate' to check the change in position

The next step is to get a click on the map to fill Me.Easting and Me.Northing.

Manifold User Community Use Agreement Copyright (C) 2007-2011 Manifold Software Limited. All rights reserved.