View Full Version : Checking for a pre-existing pushpin set

02-14-2014, 08:51 AM
hi All,

Sorry to join the forum and start with a question but I'm stuck and search isn't throwing up anything useful on the terms I'm using.

I'm calling MapPoint from Access VBA to create a series of pushpin sets. I'm able to create a new pushpin set and put the pushpins into it, but there are times that I will need to re-open the mappoint file and repeat the task. That's fine if I'm putting in new pushpinsets, but if the pushpinset already exists then I'm stuck.

Is there a way of checking to see if a pushpinset exists before trying to create it?

Here is the code I have at the moment
rsCellID is an ADODB.recordset. For each CellID record there will be a recordset of locations to create pushpins for. I want a separate pushpinset for each CellID containing a pushpin for each location record in the CellID locations recordset

'Open mappoint, creating a blank map if none is set
Set objApp = CreateObject("Mappoint.Application")
If bMapFileExists Then
Set objMap = objApp.OpenMap(strFileName)
Set objMap = objApp.NewMap
End If

'Map all the cellIDs
If Not (rsCellIDs.EOF And rsCellIDs.BOF) Then
Do Until rsCellIDs.EOF
If IsNull(rsCellIDs![CellID]) Then GoTo NoCellIDsButAreWiFiSSIDs
Set objPPSet = objMap.datasets.AddPushPinSet("Cell " & rsCellIDs![CellID])

I don't mind deleting the pushpinset (and its pushpins) if it already exists as they will be re-created anyway. Actually, that probably leads me in to the next problem, but I'll tackle that when I get to it.

Thanks for any helpful pointers you can provide.


Eric Frost
02-14-2014, 03:02 PM
Hi David,

Welcome to the forums!

There's probably a more elegant way, but the first thing that comes to mind is to use an On Error statement and trap an error. Something like:

Sub Something()
Dim bLayerExists As Boolean
bLayerExists = True

On Error Goto LayerDoesNotExist
Debug.Print MAP.Datasets("My Pushpins").Name
On Error Goto 0

Exit Sub

bLayerExists = False
Resume Next

End Sub

02-17-2014, 05:34 AM
Thanks Eric,

Catching the error was my plan B. For the moment I've gone to plan C and delete then re-create the map, but your option will probably be quicker.


05-02-2014, 10:14 AM
Equally sorry for a belated response...I just happened back to the forum after some time away from it.

A PushpinSet is just a type of DataSet. Rather than waiting for the error to occur, why not prevent it by comparing the names of the DataSets already on the map against the name you will use when creating the new DataSet, then deleting that DataSet if found?

Assuming you have already run the first few lines of your code to dimension open the map and set the current map as objMap (as in your original post), here is a bit of air code (not tested, but consistent with a lot of my other code that manipulates DataSets--feel free to post back if it does not work).

Dim dsMapPoint as Object
Dim PushpinSetName as String 'the name you need to check to avoid the error
Dim DataSetName as String 'variable for checking existing DataSet names
PushPinSetName = "My pushpin set name"
For Each dsMapPoint In objMap.DataSets
DataSetName = dsMapPoint.Name
If DataSetName = PushpinSetName Then 'if the name matches
dsMapPoint.Delete 'delete the current DataSet
Exit For 'quit looking at other DataSets for the same name, since it was just found and deleted

05-02-2014, 10:16 AM
...and I did not go through the code to loop through & delete all the individual pushpins if required, since your initial post indicates you know how to do that part.