Hi,

I'm new to the group, so greetings all!

I'm working on an application try to respond to events in Microsoft Access using Python and win32com. However, I'm having trouble in setting up the event handlers. I can think of 2 approaches both of which yield win32com errors.

First is the approach used the MSOfficeEvents.py test program. The problem is that the events to be picked up are not on the Application object but on a Form object created from it.

class   AcEvents
  def OnActivate(self):
      print "Hello from Access"
      return 1

<snip>
      self. ac = Dispatch ("Access.Application")
      self. db = self. ac. NewCurrentDatabase ("d:\\pyhack\\foo")
      self. fm = self. ac. CreateForm ()
      self. ac. Visible = true
      self. fm = DispatchWithEvents (self. fm, AcEvents)

blows out with

self. fm = DispatchWithEvents (self. fm, AcEvents)
File "D:\PYTHON22\Lib\site-packages\win32com\client\__init__.py", line 258, in DispatchWithEvents
clsid = disp_class.CLSID
AttributeError: 'NoneType' object has no attribute 'CLSID'.


I also tried a variety of string arguments, but all of those also yielded an invalid class id error.

The other approach is more Visual Basic like:

      self. ac = Dispatch ("Access.Application")
      self. db = self. ac. NewCurrentDatabase ("d:\\pyhack\\foo")
      self. fm = self. ac. CreateForm ()
      self. ac. Visible = true
      self. ev = AcEvents ()
      self. fm. OnActivate = self. ev. OnActivate

this couldn't set the OnActivate attribute with the following error.

File "D:\pyhack\1\Bob.py", line 132, in DoAccess
self. fm. OnActivate = self. ev. OnActivate
File "D:\PYTHON22\Lib\site-packages\win32com\client\__init__.py", line 503, in __setattr__
d.__setattr__(attr, value)
File "D:\PYTHON22\Lib\site-packages\win32com\client\__init__.py", line 463, in __setattr__
self._oleobj_.Invoke(*(args + (value,) + defArgs))
TypeError: Objects of type 'instance method' can not be converted to a COM VARIANT



Anyone know how to do this, either strategy is fine.

Thanks

Robert Kaplan
(Remove XX for e-mail)
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to