Anomality with ActiveControl property?

J

JotKa

Marsh Barton wrote on Feb 3, 2006 in another newsgroup how to determine if a
control currently has the focus:
If Me.ActiveControl.Name = "particular control name" Then

If my control is named e.g. "btnMyButton", this is (within the form's
module) equivalent to:

If ActiveControl.Name = btnMyButton.Name Then

This works fine; thanks for the hint! Have you got an idea, why the
following does NOT work, though in my opinion it should:

If ActiveControl = btnMyButton Then

This was my first attempt, yielding error "object does not support this
property or method". What property or method of what object does the error
message mean, and why doesn't it work?

By the way: type casting btnMyButton from Access.Button to Access.Control
has not helped.

Thanks for every further hint!

JotKa
 
A

Allen Browne

ActiveControl is an object.
btnMyButton is an object.

To compare two object references and see if they are the same object, use
the Is operator:
If Me.ActiveControl Is Me.btnMyButton
 
J

JotKa

To compare two object references and see if they are the same object, use
the Is operator:

Thanks for reminding me ... I had forgotten that VB has this special
operator. I now believe to also have the answer to my question:
This was my first attempt, yielding error "object does not support this
property or method". What property or method of what object does the error
message mean, and why doesn't it work?

The equal sign operator seems to first have the objects converted to
non-objects, i.e. tries to apply the default property or method, since none
has been provided in the code. And the CommandButton object obviously does
not have a such. Hence the error message.

Thanks for the hint, the program works now. :)

JotKa
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top