Option Compare Database
Option Explicit
Private arcMapApp As esriArcMap.Application
Public Sub setUpMap()
'Opens ArcMap, adds the shapefiles, and then modifies their representation
On Error GoTo errorHandler
[INDENT] Dim productKeyCheck As IAoInitialize
Set productKeyCheck = New AoInitialize
'We check to make sure that no other instances are running with this key
If productKeyCheck.IsProductCodeAvailable(esriLicenseProductCodeArcView) Then
'Initialize ArcView
[INDENT] productKeyCheck.Initialize esriLicenseProductCodeArcView
openMapTemplate
addShapeFiles[/INDENT]
Else
[INDENT] MsgBox "Product Code Unavailable For Use", vbExclamation, _
"Product Code Unavailable"[/INDENT]
End If
productKeyCheck.Shutdown
Set productKeyCheck = Nothing[/INDENT]
Exit Sub
errorHandler:
MsgBox Err.Description, vbExclamation, "Error in setUpMap"
End Sub
Private Sub openMapTemplate()
'Opens ArcMap and sets the global variables
On Error GoTo errorHandler
[INDENT] Dim arcMapDocument As MxDocument
Set arcMapDocument = New MxDocument
Set arcMapApp = arcMapDocument.Parent
arcMapApp.OpenDocument CurrentProject.Path & "\Distribution_Plot_Template.mxd"
Set arcMapDocument = Nothing
[/INDENT]Exit Sub
errorHandler:
MsgBox Err.Description, vbExclamation, "Error in openMapTemplate"
End Sub
Private Sub addShapeFiles()
'Adds the shapefiles to the map template
On Error GoTo errorHandler
[INDENT] Dim pMap As IMap
Dim pFeatureLayer As IFeatureLayer
Dim pFeatureWorkspace As IFeatureWorkspace
Dim pMxDocument As IMxDocument
Dim pWorkSpaceFactory As IWorkspaceFactory
Set pWorkSpaceFactory = New ShapefileWorkspaceFactory
Set pFeatureWorkspace = pWorkSpaceFactory.OpenFromFile(CurrentProject.Path & _
"\Claim_Shapefile\", arcMapApp.Hwnd)
'Set up the feature Layer
Set pFeatureLayer = New featureLayer
Set pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass("Goldstone_Brookbank_Claims_605")
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName
pFeatureLayer.Visible = True
'Get the document
Set pMxDocument = arcMapApp.Document
'Initialize the map and add the shape file to it
Set pMap = pMxDocument.FocusMap
pMap.AddLayer pFeatureLayer
Set pMap = Nothing
Set pMxDocument = Nothing
Set pFeatureLayer = Nothing
Set pFeatureWorkspace = Nothing
Set pWorkSpaceFactory = Nothing[/INDENT]
Exit Sub
errorHandler:
Set pMap = Nothing
Set pMxDocument = Nothing
Set pFeatureLayer = Nothing
Set pFeatureWorkspace = Nothing
Set pWorkSpaceFactory = Nothing
MsgBox Err.Description, vbExclamation, "Error in addShapeFiles"
End Sub
Your major problem seems to be your shapefile. Something wrong with your shapefile. Try to use Toolbox FeatureClasstoShapefile to generate your shapefile from Access if you can and see the result manually.
Private Sub openMap(filename As String)
'Opens the given file in ArcMap
[INDENT] Dim arcMapDocument As MxDocument
Set arcMapDocument = New MxDocument
Set arcMapApp = arcMapDocument.Parent
arcMapApp.OpenDocument filename
Set arcMapDocument = Nothing[/INDENT] End Sub
'Initialize the map and add the shape file to it [INDENT]Set pMap = pMxDocument.FocusMap
pMap.AddLayer pFeatureLayer
arcMapApp.SaveAsDocument CurrentProject.Path & "\MapCopy.mxd"
arcMapApp.Shutdown
openMap CurrentProject.Path & "\MapCopy.mxd"[/INDENT]