Greetings and win32 com events question

Discussion in 'Python' started by Robert Kaplan, Jan 28, 2005.

  1. 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)
     
    Robert Kaplan, Jan 28, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. makaroy

    greetings

    makaroy, Jun 9, 2007, in forum: C Programming
    Replies:
    23
    Views:
    942
    Nick Keighley
    Jun 11, 2007
  2. Daniel

    Greetings

    Daniel, Jul 24, 2007, in forum: C Programming
    Replies:
    0
    Views:
    435
    Daniel
    Jul 24, 2007
  3. Greetings

    , May 15, 2008, in forum: Python
    Replies:
    0
    Views:
    347
  4. FutureShock

    Re: Greetings

    FutureShock, Dec 25, 2008, in forum: HTML
    Replies:
    0
    Views:
    400
    FutureShock
    Dec 25, 2008
  5. Michael Edmonson

    Win32::SAPI4 question (Win32 events and Perl)

    Michael Edmonson, Feb 28, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    211
    Michael Edmonson
    Feb 28, 2004
Loading...

Share This Page