title: Problem returning object from VB.NET COM Assembly into VBA (Access)
body: <p>I have an assembly in VB .NET 2.0 that I am trying to use to call a webservice.</p>
  
  <p>This will be COM visible, and return the results to Access in VBA.</p>
  
  <p>The .NET Assembly passes all tests and executes perfectly.</p>
  
  <p>I was experiencing "Object does not support this property or method" errors when calling the methods from VBA.</p>
  
  <p>I broke it down to a certain object that was being returned and added some test methods to the .NET DLL.</p>
  
  <p>There is a "Patient" object I want to return.
  It looks like this (made it very very simple to test it):</p>
  
  <pre><code>Option Strict On
  Option Explicit On
  
  &lt;ComClass(Patient.ClassId, Patient.InterfaceId, Patient.EventsId)&gt; _
  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
  </code></pre>
  
  <p>So about as simple as an object can be really.</p>
  
  <p>I have a method that just returns a dummy record, just to test it:</p>
  
  <pre><code>Public Function GetPatientTest() As Patient
          Dim patient As New Patient
  
          patient.StorePatientID = 99
  
          Return patient
      End Function
  </code></pre>
  
  <p>This fails with the afformentioned error.</p>
  
  <p>HOWEVER,</p>
  
  <p>This method succeeds!</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>Obviously no funny dependencies with these methods.</p>
  
  <p>Really really struggling with this.</p>
  
  <p>EDIT:</p>
  
  <p>Update 16/03/2011 - Added VBA script</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Update 16/03/2011 5 minutes later - Chastising myself</p>
  
  <p>Sorry, I just worked it out.</p>
  
  <p>I need to "Set" the patient variable. </p>
  
  <pre><code>Set patient = sciStore.GetPatientTest()
  </code></pre>
  
  <p>Why didn't I need to do this for the "something" variant?</p>