VBA: Drawing in a form || Mouseevent in report

I'm developing an Access2000 application and I need either to DRAW RECTANGLES IN A FORM (by VBA) or to CATCH MOUSEEVENTS (specificly the mouse coordinates) IN A REPORT (by VBA)

I managed to draw rectangles in a report and I managed to get the mouse coordinated in a form, but I need both, drawing rectangles and getting mouse coordinated - either in a form or in a report.

By the way: How can the X and Y coordinates of MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) be converted to Pixel?
LVL 1
TheFunkSoulBrotherAsked:
Who is Participating?
 
thenelsonCommented:
There is a very good reason reports do not have mouse events - you won't be able to do anything with them once you got them.  Reports are static displays of data.  The only time you can can change than or add to them is when the report is opening and formatting - the on open and format events.  Once it is viewed on the screen (and you can move your mouse over it), it is fixed.

To draw rectangles:
You can use the create control method:
Dim ctlRect As Control
    Set ctlRect = CreateControl("YourFormNameHere", acRectangle [, section[, parent[, columnname[, left[, top[, width[, height]]]]]]])
this has to be done in design mode so reading between the lines of your question, I guess this won't help you.

Depending upon what you are trying to accomplish (always a good thing to include in your question), you might be able to have a rectangle on your form and adjust it with the mouse.

How can the X and Y coordinates of MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) be converted to Pixel?
http://www.missouri.edu/~finaidtk/mcenter.htm
0
 
harfangCommented:
Hello,

As Nelson said, you can't get the mouse move events on a report. What's more you can't draw or create rectangles on forms. Nelson's suggestion of CreateControl() works only in design mode, so that it's probably useless in your case.

When I need to "create" a rectangle or a line on a form dynamically, I create it at design time and set its "Visible" property to false. I then make it visible through code when needed.

As for pixels and twips, I confess that I usually get lazy and simply use 15 twips = 1 pixel, this corresponding to the default 96 pixel/inch resolution. Formally, you would have to ask Windows what the current metrics are, using Nelson's link, or this one which seems a little less complex:

http://www.applecore99.com/api/api012.asp

Also note that all mouse events coordinates are relative to the object, (0,0) being the top left corner of the object. You can use a control's .Top and .Left properties to convert them to coordinates relative to the form. If you need absolute screen coordinates, it gets complex again, as you need  more API calls to get the form's position on the screen.

Good luck
(°v°)
0
 
harfangCommented:
Hmm, a search on MS shows that my link above is merely a copy of an article of the knowlege base. Best to go to the source, I believe:
http://support.microsoft.com/?kbid=210590

Cheers!
(°v°)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
TheFunkSoulBrotherAuthor Commented:
Thanks very much,
I think it will work fine whith the CreateControl method, if it's possible to assign eventhandlers to a so created control.

Specificly I'd need to assign a Click() eventhandler to the ctRect
0
 
harfangCommented:
Well. The CreateControl method is available only in design view. So you can adjust all properties, including the strings for the event handlers. Use "=SomeFunction()" or "[Event procedure]" to call a VB handler. The handlers can of course be written through code as well, which is exactly what some of the control wizards do.

But again, there is no way to create any control on a form in form view. If you need a rectangle to pop-up as a response to some user interaction, that rectangle must exist beforehand.

Cheers!
(°v°)
0
 
TheFunkSoulBrotherAuthor Commented:
In my case it doesn't matter that CreateControl is only available in design view because I always redraw the whole form - so first, I open the form in design view, create rectangles an add eventhandlers, then I save the form, close it and open it in normal view.

Thanks a lot!
0
 
thenelsonCommented:
Glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.