PDA

View Full Version : Obect Required error in opening Datasets



JosephDj
02-25-2014, 01:26 PM
Hi, I'm very new to mappoint and VBA. I'm getting an "object required" error using the below VBA. What do I need to add/change? Thanks!



'open Mappoint
Dim MPApp As Object
Set MPApp = CreateObject("MapPoint.Application.NA.19")
MPApp.Visible = True
'import data
Dim objDataSets As MAPPOINT.DataSets
Dim objDataSet As MAPPOINT.DataSet
Dim zDataSource As String
zDataSource = "my file"
Set objDataSets = objApp.ActiveMap.DataSets
Set objDataSet = objDataSets.ImportData(zDataSource)

Eric Frost
02-26-2014, 09:12 AM
Hi Joseph DJ,

Welcome to the forums!

On what line specifically are you getting the error?

If you don't have a reference to MapPoint you would have to define these like this:



Dim objDataSets As Object 'MAPPOINT.DataSets
Dim objDataSet As Object 'MAPPOINT.DataSet


To set a reference, go to Tools or Project | References and then add Microsoft MapPoint.

Once you've done that, you can also declare MPApp like this:



Dim MPApp As MapPoint.Application 'Object


The advantage of setting a reference, is that you then get "context-sensitive" help, i.e. it's easier program.

If that's not the issue, the other thing that sticks out for me as a possible issue is the ImportData statement.

First, the zDataSource looks maybe too simple. You'd probably want the full path and file extension, e.g.



zDataSource = "c:\work\my file.xlsx"


Also, doesn't ImportData need to know the file type? It would be specified in another parameter. See the example code in the Help file.

I hope this helps!

Eric