AX Control's Absolute Location in Access Form 
Author Message
 AX Control's Absolute Location in Access Form

I have written an AX control in VB which, when activated, presents the user
with a selection.  This selection is presented on a small separate VB form
that I manually position directly below the location of the AX control
itself.  The effect for which I was striving is that similar to a combo box
or the date/time picker control, where the control appears to "DropDown".
In order to place the AX control's selection form from within the AX
control's class module, I set a reference to the AX control's parent and use
that to obtain both the containing form's .Top and .Left properties and the
AX control's .Top and .Left properties within the containing form.  I can
then calculate where on the screen to place the small form that is to
appear.  The code from the AX control that accomplishes this follows:

        Dim oContainer As Object
        Dim strMyName As String
        Dim lMyTop As Long
        Dim lMyLeft As Long

        strMyName = UserControl.Ambient.DisplayName
        Set oContainer = UserControl.Parent
        MsgBox oContainer.Name
        lMyTop = oContainer.Controls(strMyName).Top + oContainer.Top +
lTopOffset
        lMyLeft = oContainer.Controls(strMyName).Left + oContainer.Left +
lLeftOffset

(lTopOffset and lLeftOffset are constants that are defined elsewhere.)

Note that I declared the container as an "Object" rather than a "Form".  I
did this realizing that the Access forms library is a different collection
of objects than that used in VB6.

This approach works perfectly when I test the AX control in a VB test app.
When I place the AX on an Access form, however, I get an OLE Automation
error at the lines where I attempt to reference oContainer.Top and
oContainer.Left.  I am assuming that this is because an Access form has no
.Top or .Left property, where a VB form does.  (I actually made a call to
oContainer.Name -- successfully -- from within the AX class module just to
make sure that there wasn't some other problem, as with OLE automation or
something.)

An inspection of the properties that an Access form *does* have doesn't
reveal anything that might return its location on the screen.

If I simply remove the code that attemps to determine the AX control's
location in space the remainder of the AX control works just as desired.
The only problem is that the selection form appears in the upper-left corner
of the screen rather than below the AX control, as desired.

My question is this:  Is there a way that I can obtain -- from within the AX
control's class module -- the position on the screen of the AX control's
containing object when that containing object as an Access Forms 2.0 Form?
Alternately, is there a way that I can force Access to let me instantiate a
standard Form object and use that to contain this AX control?

I've considered simply designing this entire form in VB and packaging it all
as an AX control that I can call from within the Access app.  This one VB
form wouldn't behave as an MDI child, like all the other Access forms in the
app, but would permit me to use the AX control that I just wrote.

Comments or suggestions are welcome.

Thanks in advance,

--
- Greg Reed



Sat, 20 Nov 2004 03:27:32 GMT  
 AX Control's Absolute Location in Access Form
(1) Access Forms (I don't know what you mean by Access Forms 2.0 form -
sorry; are you talking about _Microsoft_ Forms, the ones usable in _other_
office applications?) _do_ have a .Top and .Left property.

(2) Have you considered using a control array, with your VB control, instead
of a separate VB form, for the dropdown? It seems to me that would be
simpler.


Quote:
> I have written an AX control in VB which, when activated, presents the
user
> with a selection.  This selection is presented on a small separate VB form
> that I manually position directly below the location of the AX control
> itself.  The effect for which I was striving is that similar to a combo
box
> or the date/time picker control, where the control appears to "DropDown".
> In order to place the AX control's selection form from within the AX
> control's class module, I set a reference to the AX control's parent and
use
> that to obtain both the containing form's .Top and .Left properties and
the
> AX control's .Top and .Left properties within the containing form.  I can
> then calculate where on the screen to place the small form that is to
> appear.  The code from the AX control that accomplishes this follows:

>         Dim oContainer As Object
>         Dim strMyName As String
>         Dim lMyTop As Long
>         Dim lMyLeft As Long

>         strMyName = UserControl.Ambient.DisplayName
>         Set oContainer = UserControl.Parent
>         MsgBox oContainer.Name
>         lMyTop = oContainer.Controls(strMyName).Top + oContainer.Top +
> lTopOffset
>         lMyLeft = oContainer.Controls(strMyName).Left + oContainer.Left +
> lLeftOffset

> (lTopOffset and lLeftOffset are constants that are defined elsewhere.)

> Note that I declared the container as an "Object" rather than a "Form".  I
> did this realizing that the Access forms library is a different collection
> of objects than that used in VB6.

> This approach works perfectly when I test the AX control in a VB test app.
> When I place the AX on an Access form, however, I get an OLE Automation
> error at the lines where I attempt to reference oContainer.Top and
> oContainer.Left.  I am assuming that this is because an Access form has no
> .Top or .Left property, where a VB form does.  (I actually made a call to
> oContainer.Name -- successfully -- from within the AX class module just to
> make sure that there wasn't some other problem, as with OLE automation or
> something.)

> An inspection of the properties that an Access form *does* have doesn't
> reveal anything that might return its location on the screen.

> If I simply remove the code that attemps to determine the AX control's
> location in space the remainder of the AX control works just as desired.
> The only problem is that the selection form appears in the upper-left
corner
> of the screen rather than below the AX control, as desired.

> My question is this:  Is there a way that I can obtain -- from within the
AX
> control's class module -- the position on the screen of the AX control's
> containing object when that containing object as an Access Forms 2.0 Form?
> Alternately, is there a way that I can force Access to let me instantiate
a
> standard Form object and use that to contain this AX control?

> I've considered simply designing this entire form in VB and packaging it
all
> as an AX control that I can call from within the Access app.  This one VB
> form wouldn't behave as an MDI child, like all the other Access forms in
the
> app, but would permit me to use the AX control that I just wrote.

> Comments or suggestions are welcome.

> Thanks in advance,

> --
> - Greg Reed




Sat, 20 Nov 2004 03:37:44 GMT  
 AX Control's Absolute Location in Access Form

Quote:
> (1) Access Forms (I don't know what you mean by Access Forms 2.0 form -
> sorry; are you talking about _Microsoft_ Forms, the ones usable in _other_
> office applications?) _do_ have a .Top and .Left property.

> (2) Have you considered using a control array, with your VB control,
instead
> of a separate VB form, for the dropdown? It seems to me that would be
> simpler.

(1)  The controls available in MS Access (I haven't done much VBA
development in the other Office Apps) are contained in MF20.dll, "Microsoft
Forms 2.0 Object Library".  This object library includes its own versions of
label, command button, text box, list box, combo box, and so on.  I assumed
that it also contained the definition for the Form object used in Access.  I
could be mistaken about this detail.

In any event, a Form in MS Access 2000 does not have a .Top or .Left
property, among other differences from a regular VB form (such as the Header
and Footer sections or the RecordSource property).  When I attempt to pass a
reference to a MS Access form into my VB-created AX control, everything
works just fine (as proven by my ability to correctly retrieve its .Name
property from within the AX control's class module) until I attempt to make
a reference to either Top or Left -- properties that do not appear to exist
among the MS Access Form properties.  If you're using a Form in MS Access
that has a Top and Left property, please tell me how you did it.

(2) Since Access doesn't support control arrays, I'm assuming you meant to
include a control array in my AX control.  I'm not quite sure exactly what
you're trying to tell me here, so I'll give a little more detail about my AX
control:  The UserControl object itself contains only a label control and a
check box control with its .Style property set to Graphical, so that it
appears as a button.  The label control contains the data currently assigned
to the control (much like a combo box or a date time picker control).  At
run time, when the user clicks on the AX control's check box component
(which, remember, looks like a button), a modal VB form appears just below
the control (again, as with a combo box or date/time picker control).  This
position is modified so as to appear above the AX control's location on the
screen if there isn't enough screen below the AX to display the form.  This
form presents the user with a selection of valid data, arranged in a grid
(and by use of a control array, BTW, though I didn't mention that detail
before).  When the user clicks one of the selections presented, the form is
unloaded and the data selected appears in the AX control's label component.
How would you suggest using a control array to duplicate this functionality?

As I wrote before, the entire process works great when I place the AX
control on a form in VB6.  The AX control grabs a reference to its parent
and its name.  It then grabs the parent's Top and Left properties as well as
its own Top and Left properties, so that it can calculate exactly where it
is on the screen.  It then uses this information to manually place the
aforementioned selection screen when the user clicks the AX's check box
component (which looks like a button).

The entire control is designed to mimic the operation of a combo box (a
control with which most computer users are familiar and comfortable) but
with added functionality that I can't obtain with a standard combo box.  The
goal is to make the application easy to learn and use.  I am extremely
particular in how I present information and choices to users in my
applications, and believe that the particular presentation of information
that I am using with this control is ideal.

I really don't think that the details of what the AX or its selection form
actually do are important to the question at hand.  What I need to know is
how I can determine the AX control's location *on the screen* (as opposed to
its location on the parent), in twips, so that I can then place the
selection form properly.  When testing the AX control on a VB form, I can
accomplish this by grabbing the AX control's top and left properties along
with the parent form's top and left properties.  In Access, this does not
work, because no top or left properties are available for the form that
contains my AX control.  I need another way.

Thanks,

--
- Greg Reed



Sun, 21 Nov 2004 05:52:16 GMT  
 AX Control's Absolute Location in Access Form
The Controls in Microsoft Forms 2.0 Library are not, repeat NOT, the Access
Controls. The Forms in the Microsoft Forms 2.0 Library are not, repeat NOT,
the Access Forms. They are Controls and Forms intended for Word, Excel, or
other applications, are different from the builtin controls, and the only
use I have heard of them in Access is in Toolbars.

ActiveX controls have to meet specific conditions to be usable in Access --
I'm sorry that I do not know what those conditions are. But, many ActiveX
controls that work fine in VB or C++ do not work in Access.

Controls in Access have Top and Left properties -- those are relative to the
location of the Form. You are correct that the Form, itself, does not have a
Top or Left property, either in its property sheet or at runtime. I
misstated that they do and aplogize for my mistake.

My suggestion was that you use a control array within your VB-prepared
ActiveX. I was assuming that the control array was availble within a VB
ActiveX... I believe the VB runtime library must be installed to use an
ActiveX created with VB.

I'm reasonably sure that, using some appropriate API, you can get the
Top/Left of the Access window, and of the Form itself. Access Forms are one
of the few objects in Access that have a hWnd. If I were looking for this
depth of information, I'd look first at the API section of the FAQ,
http://www.mvps.org/access and then at Stephen Lebans' site
http://www.lebans.com.



Sun, 21 Nov 2004 11:06:03 GMT  
 AX Control's Absolute Location in Access Form

Quote:
> The Controls in Microsoft Forms 2.0 Library are not, repeat NOT, the
Access
> Controls. The Forms in the Microsoft Forms 2.0 Library are not, repeat
NOT,
> the Access Forms. They are Controls and Forms intended for Word, Excel, or
> other applications, are different from the builtin controls, and the only
> use I have heard of them in Access is in Toolbars.

I'll take your word for it.  I know that the controls in Access behave just
like the controls in FM20.dll.  I don't suppose you know the library when
Access' control *are* defined, do you?

Quote:
> ActiveX controls have to meet specific conditions to be usable in
Access --
> I'm sorry that I do not know what those conditions are. But, many ActiveX
> controls that work fine in VB or C++ do not work in Access.

I'll also have to take your word for this.  I've written a good dozen or so
AX controls in VB for use in Access front-ends, and all of them have worked
pretty much the same in both DE's.  (VB seems better at supporting
auto-complete and prompting at design time than Access, forcing me to either
write down or remember actual method and property names, as well as the
order of parameters passed when coding in Access.  These methods and
properties all seem to work just fine, otherwise.)  In each case, I test the
AX control initially in a VB form (just because I can run both the test app
and the AX control in debug mode -- in order to put the AX control on an
Access form it must be a compiled OCX), then compile it and use it in Access
when I have it working the way I want.

Quote:
> Controls in Access have Top and Left properties -- those are relative to
the
> location of the Form. You are correct that the Form, itself, does not have
a
> Top or Left property, either in its property sheet or at runtime. I
> misstated that they do and aplogize for my mistake.

> My suggestion was that you use a control array within your VB-prepared
> ActiveX. I was assuming that the control array was availble within a VB
> ActiveX... I believe the VB runtime library must be installed to use an
> ActiveX created with VB.

> I'm reasonably sure that, using some appropriate API, you can get the
> Top/Left of the Access window, and of the Form itself. Access Forms are
one
> of the few objects in Access that have a hWnd. If I were looking for this
> depth of information, I'd look first at the API section of the FAQ,
> http://www.mvps.org/access and then at Stephen Lebans' site
> http://www.lebans.com.

I'd hoped to avoid the API's, as I am frequently frustrated by the
documentation -- usually only C++ examples are provided, forcing me to
translate to VB in order to figure out how to use them.  I have only a
beginner's understanding of C++, so deciphering the API documentation is
often more of a chore than finding other solutions.  In this case, however,
the GetWindowPosition API turned out to be relatively straightforward, and
using it to obtain window placement, my AX now works perfectly in Access.

Thanks for your assistance.

- Greg Reed



Mon, 22 Nov 2004 06:58:41 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Finding a Control's absolute Location on the Screen

2. How to tell absolute location of a control?

3. absolute location of a control on the screen

4. Can't see properties for Ax control on userform

5. Form Location after Clicking Form's Restore Button

6. Can anybody straighten me out on accessing one form's controls from another form

7. how do i check for absolute mouse location?

8. Running VBA from relative rather than absolute file locations

9. How to access a DB's form's control from w/i VB module

10. >AX DLL's<

11. >AX DLL's<

12. >AX DLL's<

 

 
Powered by phpBB® Forum Software