PDA

View Full Version : Overloading MapPoint?



Swoop
02-04-2013, 10:03 AM
I have managed to build the following code segment which runs through a list of engineers, plots start location as a pushpin, mid point of work as a pushpin and every job completed by said engineer as a dataset.....on a new MapPoint Map and saves the output as a .ptm file named as per the engineer in question.

It all works perfectly......until I un-remark the segment of code to add a drivetime to the map as well......when that little bit of code is included then this macro will get through around 5 or 6 engineers and then crash with the error:

The instruction as "0x600337d3" referenced memory at "0x00000000". The memory could not be "read".
Click on OK to terminate the program

What am I doing wrong here?




Sub EngineerMapping(Optional SaveFile As String)

'################################################# #######################################
'############# Auto produces MapPoint output for every engineer in list ################
'############# Including all jobs, home location and mid point ################
'############# Note: Territory must be mapped in advance. ################
'################################################# #######################################

Dim objDataSets As MapPoint.DataSets
Dim objDataSet As MapPoint.DataSet
Dim objApp As New MapPoint.Application
Dim zDataSource As String
Dim TerrPath As String
Dim objTerritory As MapPoint.DataSet
Dim MPcolour As Long
Dim objMap As MapPoint.Map
Dim objDataMap As MapPoint.DataMap
Dim Engineer As String
Dim EngHomePostcode As String
Dim sweep As Integer
Dim LastJob As Integer
Dim Esweep As Integer
Dim MidPoint As String
Dim objMidPoint As MapPoint.Pushpin
Dim objHome As MapPoint.Pushpin
Dim SaveLoc As String
'Dim SaveFile As String
Dim objLoc As MapPoint.Location

Sheets("Engineers").Select
For sweep = 2 To Range("Engineers!A65000").End(xlUp).Row
Engineer = Cells(sweep, 1).Value

EngHomePostcode = Cells(sweep, 6).Value
MidPoint = Cells(sweep, 12).Value
LastJob = Range("'" & Engineer & "'!A65000").End(xlUp).Row

zDataSource = SaveFile & "!" & Engineer & "!N2:N" & LastJob

objApp.OpenMap SaveLoc & "patches.ptm"
Set objDataSets = objApp.ActiveMap.DataSets
Set objDataSet = objDataSets.ImportData(zDataSource)
objDataSet.Symbol = 17

objApp.ActiveMap.MapStyle = geoMapStyleData

Set objMap = objApp.ActiveMap
Set objMidPoint = objApp.ActiveMap.AddPushpin(objApp.ActiveMap.FindA ddressResults(, , , , MidPoint)(1))
objMidPoint.Symbol = 44

Set objHome = objApp.ActiveMap.AddPushpin(objApp.ActiveMap.FindA ddressResults(, , , , EngHomePostcode)(1))
objHome.Symbol = 26

'================================================= ==============

' ' drive time

' Set objLoc = objApp.ActiveMap.FindAddressResults(, , , , EngHomePostcode)(1)
' Set objMap.Location = objLoc
'
'
' objMap.Shapes.AddDrivetimeZone objLoc, 20 * geoOneMinute

'================================================= ===============

SaveLoc = Range("Menu!H17").Value

For Esweep = 2 To Len(Engineer)
If Mid$(Engineer, Esweep, 1) = " " Then
Engineer = SaveLoc & Left$(Engineer, 1) & Mid$(Engineer, Esweep + 1, Len(Engineer) - Esweep) & ".ptm"
Exit For
End If
Next Esweep

Set objMap = objApp.ActiveMap
objMap.SaveAs Engineer, geoFormatMap, True



Next sweep

Eric Frost
02-04-2013, 10:12 AM
Swoop,

By the way, in case I didn't say it before, Welcome to the forums! And thanks for chipping in to help answer questions already!

I would check 1st to see if it is crashing before it's not actually finding a Location for that particular Postcode, perhaps that is why it is crashing? It is rare to see MapPoint crashing ungracefully like that.

Can you post a sample spreadsheet that exhibits the issue? I can run on my computer to see if it's OK here and maybe we can narrow down what's going on. You would need to zip before attaching to a post.

Thanks and hopefully we can sort it out!

Eric

Swoop
02-04-2013, 10:21 AM
It's definately finding all the postcodes, if I leave the drive time part of the routine out then it will complete and spit out a .ptm file for every engineer with every job, mid point and home location plotted correctly (there's code elsewhere in the workbook that checks a postcode is valid and if not, replaces it with a nearby postcode and tries again).

The other issue is the data I'm using for this is heavily restricted as it contains customers personal details.....hence I can't let it outside the business network. And the database it's pulling job details from is around 2Gb in size so it's not really postable. I'll see if I can hash together some ficticious data and get back to you......

Also, in further testing it seems that (after a reboot) the code will run perfectly once.....the second time (and all subsequent times) it's run it'll crash unless the drivetime part is remarked out.

I've checked and mappoint.exe cannot be seen in task manager after running the code so it's not hanging.

Eric Frost
02-04-2013, 10:47 AM
One issue I've seen where MapPoint can crash ungracefully like this is when accessing a file repeatedly, I think this might possibly be what you are experiencing since you keep importing datasets from "zDataSource"?

A solution is to dump your data down to text files first, and then import data from separate text files, not repeatedly attacking the same file.

(What this has to do with AddDrivetimeZone and why it would work when that part is commented, I have no idea unfortunately!)

Eric Frost
02-04-2013, 10:52 AM
There's one past thread on this --
http://www.mapforums.com/memory-access-violations-14544.html

The last thing this person posted was that they were going to try CSV files.

Besides this person, I have seen this error crop up other places including for a client and we ended up going to text files.

Eric

Swoop
03-01-2013, 09:06 AM
Back to this again.....

After much banging of head against the desk, I've discovered that this line:



Set objMap.Location = objLoc


is what causes issues. Why? No idea. But leaving it out seems to cure the issue.

Eric Frost
03-01-2013, 09:27 AM
I don't see that line in your code?

What does that line accomplish anyway? Does it reposition/center the map on that location?

Eric

Swoop
03-01-2013, 09:46 AM
Exactly.

It's there, however, in the original example I posted above I'd rem'd out the section that dealt with Drive Time Zones in order to get some work done.....and had forgotten to un-rem it when posting here.

Eric Frost
03-01-2013, 09:56 AM
Oh right OK. How did I miss that! I actually pasted into Notepad and searched, lol.

I honestly have no idea why that would crash it. Maybe the map just doesn't want to be wiggled too much. Or it's picky about the neighborhoods you try to zoom to...