Object variable or With block variable not set (Error 91) 
Author Message
 Object variable or With block variable not set (Error 91)

Hi Iam trying to run the code below and get this error command.  Can anyone
tell me ehat is wrong here.

Thanks

Option Explicit
Dim oMpApp As MapPoint.Application
Dim oMap As MapPoint.Map
Private Sub Command1_Click()
   oMap.Shapes.AddShape geoShapeOval, _
   oMap.GetLocation(49.01807, -121, 9), 10, 10
      ' Try to attach to running instance of MapPoint
   On Error Resume Next
   Set oMpApp = GetObject(, "MapPoint.Application")
   On Error GoTo 0

   If oMpApp Is Nothing Then
      ' Attaching failed - try creating an object
      On Error Resume Next
      Set oMpApp = CreateObject("MapPoint.Application")
      On Error GoTo 0

      If oMpApp Is Nothing Then
         MsgBox "Could not create MapPoint object"
         End
      End If
      ' make the app visible
      oMpApp.Visible = True
   End If

   ' Ensure MapPoint survives when app terminates
   oMpApp.UserControl = True

   ' Retrieve the active map
   Set oMap = oMpApp.ActiveMap
End Sub



Tue, 03 May 2005 05:26:33 GMT  
 Object variable or With block variable not set (Error 91)

Quote:

> Hi Iam trying to run the code below and get this error command.  Can
> anyone tell me ehat is wrong here.

1) It's VB/VBA code, not VBScript (in case you missed it, this is a VBScript
newsgroup ;-).

2) You never actually set oMap to be an instance of a MapPoint.Map (at least
not in the code you posted).

Quote:

> Option Explicit
> Dim oMpApp As MapPoint.Application
> Dim oMap As MapPoint.Map
> Private Sub Command1_Click()
>    oMap.Shapes.AddShape geoShapeOval, _
>    oMap.GetLocation(49.01807, -121, 9), 10, 10
>       ' Try to attach to running instance of MapPoint
>    On Error Resume Next
>    Set oMpApp = GetObject(, "MapPoint.Application")
>    On Error GoTo 0

>    If oMpApp Is Nothing Then
>       ' Attaching failed - try creating an object
>       On Error Resume Next
>       Set oMpApp = CreateObject("MapPoint.Application")
>       On Error GoTo 0

>       If oMpApp Is Nothing Then
>          MsgBox "Could not create MapPoint object"
>          End
>       End If
>       ' make the app visible
>       oMpApp.Visible = True
>    End If

>    ' Ensure MapPoint survives when app terminates
>    oMpApp.UserControl = True

>    ' Retrieve the active map
>    Set oMap = oMpApp.ActiveMap
> End Sub

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US


Tue, 03 May 2005 05:45:12 GMT  
 Object variable or With block variable not set (Error 91)

Quote:
> 2) You never actually set oMap to be an instance of a MapPoint.Map
> (at least not in the code you posted).

Just noticed that you do, but way too late in the code...

Quote:

>> Private Sub Command1_Click()
>>    oMap.Shapes.AddShape geoShapeOval, _
>>    oMap.GetLocation(49.01807, -121, 9), 10, 10
---snip---
>>    Set oMap = oMpApp.ActiveMap
>> End Sub

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US


Tue, 03 May 2005 07:52:22 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Multi-field lookup

2. Object variable or With block variable not set (Error 91) Please Help

3. Object variable or With block variable not set (Error 91)

4. error 91 Object Variable o on with block variable is not set

5. Runtime error 91/Object variable or With block variable not set problems

6. runtime error: 91 Object variable or with block variable not set

7. Run Time Error 91: Object variable or With Block variable not set

8. VB 5.0 - Error:91 Object Variable Or With Block Variable Not Set

9. Error 91 Object variable or With-Block, variable not set

10. Error 91-Object or block with variable not set

11. error 91 - object or block with variable not set

12. Debugging COM+ Componets -- Runtime error 91- Object variable or with block not set

 

 
Powered by phpBB® Forum Software