title: COM object in VB 6: user-defined type not defined
body: <p>In a VB6 project I have added reference to the COM dll: c:\windows\system32\locationapi.dll</p>
  
  <p>The following code works perfectly well and the object's methods/properties can be accessed correctly:</p>
  
  <pre><code>Public civicfactory
  Set civicfactory = CreateObject("LocationDisp.CivicAddressReportFactory")
  </code></pre>
  
  <p>However, its events don't work - I cannot catch them. I guess I need to declare the object like this:</p>
  
  <pre><code>Public WithEvents civicfactory As LocationDisp.CivicAddressReportFactory
  </code></pre>
  
  <p>But this gives me the error "User-defined type not defined" at this line.</p>
  
  <p>Can anyone tell me why it says so while the first code works perfectly well?</p>
  
  <p>And as my purpose is to get event handlers working, can you point out any error or anything missing in my code:</p>
  
  <pre><code>Public civicfactory
  Private Sub civicfactory_NewCivicAddressReport(report)
      MsgBox "New civic address report arrived"
      DisplayCivic (report)
  End Sub
  Set civicfactory = CreateObject("LocationDisp.CivicAddressReportFactory")
  civicfactory.ListenForReports (1000)
  </code></pre>
  
  <p>Similar code works in VBScript, but I cannot get it working in VB 6 - the event handler never gets called.</p>
  
  <p>Thanks in advance!</p>