Drawing lines/rectangles using VBA (1 Viewer)

G37Sam

Registered User.
Local time
Today, 21:00
Joined
Apr 23, 2008
Messages
454
Is it possible to draw a line or rectangle on a form using VBA?
 

ChrisO

Registered User.
Local time
Tomorrow, 03:00
Joined
Apr 30, 2003
Messages
3,202
Yes, there is a demo here.

What you would be looking for is:-
Public Sub Polygon()

and change:-
.Radius.DataType.Value to whatever
.Aspect.X.DataType.Value to whatever
.Aspect.Y.DataType.Value to whatever
.Start.DataType.Value = 45
.Sides.DataType.Value to 4.

Chris.
 

G37Sam

Registered User.
Local time
Today, 21:00
Joined
Apr 23, 2008
Messages
454
Thanks for your response Chris, the demo attached seems to be much more advanced than I'm looking for

I'm looking to have the user click on a button, that will draw a line or rectangle with at a certain location, is there no simpler function/solution?
 

ChrisO

Registered User.
Local time
Tomorrow, 03:00
Joined
Apr 30, 2003
Messages
3,202
It is not easy to draw on Forms.

At its simplest you could have 1 rectangle Object and move it to the appropriate position on button click.
But how do you set the position of the rectangle? If the position is constant then you don’t have to move it, all you would need to do it make it visible.

And what happens if the user clicks the button more that once?

If we knew more about what you are trying to do we may be able to help.

Chris.
 

G37Sam

Registered User.
Local time
Today, 21:00
Joined
Apr 23, 2008
Messages
454
I figured I'd spare you the boring details but if you're interested then welcome on board mate :)

This is for an Exhibition Stand Reservation database. The firm rents out a certain space and breaks it down into smaller stands.

I'm thinking it'd make a nice interface if I can have the user specify number of stands, along with their lengths and widths to somehow draw them on the form. Of course, I'd store the values in a table in order for them to be displayed on a report later something like this:

http://www.ctauk.org/UserFiles/Images/Events/Access10/Access10_FloorPlan.jpg
 

ChrisO

Registered User.
Local time
Tomorrow, 03:00
Joined
Apr 30, 2003
Messages
3,202
Maybe the Access 2003 attachment will help.

Chris.
 

Attachments

  • DragAndDrop_A2003.zip
    69.6 KB · Views: 1,629

G37Sam

Registered User.
Local time
Today, 21:00
Joined
Apr 23, 2008
Messages
454
Thanks for sharing that Chris!

So it seems like the only way to do this would be to have all the boxes predrawn in design view, and then make the ones I need visible, move them around and alter their widths and heights.
 

ChrisO

Registered User.
Local time
Tomorrow, 03:00
Joined
Apr 30, 2003
Messages
3,202
I wouldn’t say the only way but it is the way I did it with a re-calculating Gantt chart for labour and hire costs. But it’s all the same thing, the user drags/drops/re-sizes with the mouse. You could also include snap to grid on a scale for sizing stands. The physical size of the stands could then be controlled so you don’t inadvertently use too much space.

But the boxes will need to be pre-drawn in design view because you can not construct boxes/labels at runtime. To do so requires going into design view and that can’t be done in an MDE file. So, if you go the way of constructing boxes/labels at runtime you limit the project to an MDB file and that’s not such a good thing.

I’m not saying it’s easy but you do end up with a better product.

Chris.
 

EaleyP

New member
Local time
Today, 18:00
Joined
Jan 3, 2015
Messages
2
Maybe the Access 2003 attachment will help.

Chris.

Chris, I would very much like to understand more how this example works as I need to be able to do something similar i.e. pick a transparent box, overlay it on an image and resize and remember the co-ordinates.

If you can help, please can you contact me on my email
Phil.Ealey ignore bit
@ ignore bit
BTinternet.com


Thanks Phil
 

EaleyP

New member
Local time
Today, 18:00
Joined
Jan 3, 2015
Messages
2
Phil, I didn't want you to feel ignored, but Chris passed away last year:



You might want to start a new thread with your question, referencing this one for context.

I'm really sorry to hear that. He was obviously very talented and I suspect very much missed. Thank you for letting me know.

Regards Phil
 

Users who are viewing this thread

Top Bottom