?
Solved

VBA: Drawing in a form || Mouseevent in report

Posted on 2006-03-25
7
Medium Priority
?
857 Views
Last Modified: 2008-03-10
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?
0
Comment
Question by:TheFunkSoulBrother
  • 3
  • 2
  • 2
7 Comments
 
LVL 39

Accepted Solution

by:
thenelson earned 600 total points
ID: 16288360
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
 
LVL 58

Expert Comment

by:harfang
ID: 16288723
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
 
LVL 58

Assisted Solution

by:harfang
harfang earned 200 total points
ID: 16288736
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 1

Author Comment

by:TheFunkSoulBrother
ID: 16289274
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
 
LVL 58

Expert Comment

by:harfang
ID: 16290623
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
 
LVL 1

Author Comment

by:TheFunkSoulBrother
ID: 16309921
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
 
LVL 39

Expert Comment

by:thenelson
ID: 16312894
Glad to help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question