Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an assembly in VB .NET 2.0 that I am trying to use to call a webservice.

This will be COM visible, and return the results to Access in VBA.

The .NET Assembly passes all tests and executes perfectly.

I was experiencing "Object does not support this property or method" errors when calling the methods from VBA.

I broke it down to a certain object that was being returned and added some test methods to the .NET DLL.

There is a "Patient" object I want to return. It looks like this (made it very very simple to test it):

Option Strict On
Option Explicit On

<ComClass(Patient.ClassId, Patient.InterfaceId, Patient.EventsId)> _
Public Class Patient

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class 
    ' and its COM interfaces. If you change them, existing 
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "672dfbd9-8f3a-4ba2-a33d-89fef868f2b9"
    Public Const InterfaceId As String = "74a9c54c-4427-4d31-8220-3258ecda345d"
    Public Const EventsId As String = "dc25515e-1bb7-4a66-97d5-270c00d792a9"
#End Region

    Public Sub New()

        MyBase.New()

    End Sub

    Public Property StorePatientID() As Integer
        Get
            Return m_StorePatientID
        End Get
        Set(ByVal value As Integer)
            m_StorePatientID = value
        End Set
    End Property
    Private m_StorePatientID As Integer
End Class

So about as simple as an object can be really.

I have a method that just returns a dummy record, just to test it:

Public Function GetPatientTest() As Patient
        Dim patient As New Patient

        patient.StorePatientID = 99

        Return patient
    End Function

This fails with the afformentioned error.

HOWEVER,

This method succeeds!

Public Function GetPatientArrayTest() As Patient()

        Dim strings As New List(Of Patient)
        Dim patient As New Patient

        patient.StorePatientID = 99

        strings.Add(patient)

        Return strings.ToArray

    End Function

The DLL is made com visible through "Properties" page. Builds to project/bin/debug, always do a rebuild. Always seems to be updated with new methods etc when I look at it in VBA so don't think it's looking at an old version.

Obviously no funny dependencies with these methods.

Really really struggling with this.

EDIT:

Update 16/03/2011 - Added VBA script

Public Function FindPatientsTest(ByVal surname As String, ByVal surnameBeginsWith As Boolean, ByVal forename As String, ByVal forenameBeginsWith As Boolean, ByVal dateOfBirth As String)


Dim token As String
token = Login()

Dim patient As SCIStoreWS60.patient
Set patient = New SCIStoreWS60.patient

'// This doesn't work.
'// When adding a "Watch" to the function, I can see it returns an "Object/Patient" and is the correct results
'// When adding a "Watch" to the variable "patient" I can see it is a "Patient/Patient"
patient = sciStore.GetPatientTest()

'// This works fine
Dim something As Variant
something = sciStore.GetPatientArrayTest()

End Function

Update 16/03/2011 5 minutes later - Chastising myself

Sorry, I just worked it out.

I need to "Set" the patient variable.

Set patient = sciStore.GetPatientTest()

Why didn't I need to do this for the "something" variant?

share|improve this question
    
Post the failing vba code as well. –  Hans Passant Mar 15 '11 at 23:10
    
Can you also included in your VBA code confirmation your "succeeding" array return actually contains a Patient with ID 99 accessible from Access? –  Mark Hurd Mar 16 '11 at 2:54
    
Sure, added the VBA script. I can see through the "watch" that the function is actually returning an "Object/Patient", and the patient it is returning it correct. So appears as though the function is being called correctly. It just looks like VBA is having a problem assigning the result to the variable I am declaring? –  Marc Lang Mar 16 '11 at 9:17
    
Just worked it out. Needed to "set" the patient variable. Occam's razor. When you start judging the funadmental workings of COM/Visual Basic, you've probably made a daft ommision. –  Marc Lang Mar 16 '11 at 9:30

1 Answer 1

So, yes, you need to Set object references, but not arrays.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.