472,804 Members | 1,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,804 software developers and data experts.

"Cloning" a control and its event code

I've read up on Access and the limits of creating visible controls at
run-time.
I'm using Access 2003 and assume that it cant be done.

I did find a clever method of having a main form (and in it's code)
open up a subform in design mode (hidden maybe) and then using the
CreateControl method, create controls.
Save the subform and set a subform control on the main form to point to
the subform (really a form) I just edited/designed.

What I would like to know is....

Can I have a control on that subfom, say a rectange (with all its code
I put in for click events), and "clone" it (along with the event code I
created) on the subform, of course multiple times as needed? So, that
the "cloned" rectangles also have the click event code I made for the
original.

This way I can create as many as I like and the functionality of each
rectangle is the same.
Thanks in advance for any advice.

Jun 2 '06 #1
6 2198
I'd say that on a subform, if your rectangle is in the detail section, and
if your subform is in continuous or datasheet view, then your rectangle will
naturally propagate to each "instance" of the detail section. In other
words, for every record in the subform, you will naturally see the whole
detail section laid out identically.

I'm having a hard time understanding why you might need to clone a rectangle
and its events. Can you say more about why you need to do this? You might
not have to take this approach.
Jun 2 '06 #2
Sure Rick,

It's the same old story. I want to create a certain amount of
rectangles based on the amount of records in a table (which can vary)
and update the subform for any new or deleted records (also some other
info if the record has been changed, but not deleted).
But, unlike what everybody thinks, which is some kind of continuous
form of controls based on the records, I want to create a kind of
"Matrix", a nxn grid of rectangles.

So, the user has an interface, say the Main form, to
browse/update/delete the records (in a subform datasheet) and then
click a button that will generate the grid.
The grid will be on a form and shown in a subform control after
created.

Now, once the grid is generated, each rectangle should have the click
event code to respond to the user, who will click each rectangle as
needed and change the color of the rectangle clicked. There are
multiple colors which each mean something different.

When the user clicks a rectangle, a cooresponding record in the table
is updated.
If the user deletes or adds a record, a row of rectangles is added or
removed.

Mathematically (if I have this right) it is a "Cartesian Cross Product"
of the records in
a table with itself. Kind of like how a multiplication or addition
table looks.
The record id is at top and across, labeling each column in the grid,
and at the left
and down, labeling each row in the grid. The user marks the color of
each grid based
on the condition or meaning of combination of a row and column id
value.
Naturally, like squares in a multiplication table, the diagonal
rectangles would represent the pair (id,id).

So given a table with n records, create an nxn grid, labeling the top
and left with the record id, and allowing the user to click a rectangle
to change its color, update the table with the color value chosen after
the click event.

Now, one could, theoretically, upon creating the grid, calculate the
cross product pairs and populate another table, and with that other
table somehow generate each rectangle, of course with the same click
event features as above.
Hope this helps and thanks for responding,

Christopher

Rick Wannall wrote:
I'd say that on a subform, if your rectangle is in the detail section, and
if your subform is in continuous or datasheet view, then your rectangle will
naturally propagate to each "instance" of the detail section. In other
words, for every record in the subform, you will naturally see the whole
detail section laid out identically.

I'm having a hard time understanding why you might need to clone a rectangle
and its events. Can you say more about why you need to do this? You might
not have to take this approach.


Jun 2 '06 #3
If there's any way of knowing ahead of time the maximum number of
rectangles, you might be better off creating all of them ahead of time in
design view. Then hide or reveal them based on your data.

Access is pretty object oriented, but it's not enough so, I think, for you
to be able to create your subform as an object and then create controls as
objects and add them to the collection as you could in flavors of C or VB
these days.

If having them all, and hiding or revealing, is good enough, you would be
able to load up the tag property of each rectangle with values needed to
accomplish the task related to that rectangle. As you click even, use
"=MyClickEvent()".

IN your module (subform, down where the rectangles are) you need a public
function named MyClickEvent. It would refer to Screen.ActiveControl to get
to the clicked rectangle. E.G.:

dim c as control
set c = screen.activecontrol
c.backcolor = vbwhite
if c.tag = "You Win" then
msgbox "Hot dog!"
else
msgbox "Try again"
endif

Would that help you?

By the way, if you're not showing multiple records, why put this in a
subform? There are plenty of other reasons, but if it's okay I'd like to
ask yours.
Jun 2 '06 #4
Thanks Rick,

I was using a subform in order to open it hidden in design mode, create
all the rectangles, save, then show the subform in a subform control on
the Main form. Another subform on the Main form will have the records
to create the rectangles by.

Hope this helps,

Christopher

Rick Wannall wrote:
If there's any way of knowing ahead of time the maximum number of
rectangles, you might be better off creating all of them ahead of time in
design view. Then hide or reveal them based on your data.

Access is pretty object oriented, but it's not enough so, I think, for you
to be able to create your subform as an object and then create controls as
objects and add them to the collection as you could in flavors of C or VB
these days.

If having them all, and hiding or revealing, is good enough, you would be
able to load up the tag property of each rectangle with values needed to
accomplish the task related to that rectangle. As you click even, use
"=MyClickEvent()".

IN your module (subform, down where the rectangles are) you need a public
function named MyClickEvent. It would refer to Screen.ActiveControl to get
to the clicked rectangle. E.G.:

dim c as control
set c = screen.activecontrol
c.backcolor = vbwhite
if c.tag = "You Win" then
msgbox "Hot dog!"
else
msgbox "Try again"
endif

Would that help you?

By the way, if you're not showing multiple records, why put this in a
subform? There are plenty of other reasons, but if it's okay I'd like to
ask yours.


Jun 2 '06 #5
Rick,

Is there another way to get the id of the rectangle clicked in the
subform?
Apparently there is no focus for rectangle so Screen.ActiveControl is
not working.

I may have to hard code names or use mouse coordinates, any ideas?

Thanks

ce*******@yahoo.com wrote:
Thanks Rick,

I was using a subform in order to open it hidden in design mode, create
all the rectangles, save, then show the subform in a subform control on
the Main form. Another subform on the Main form will have the records
to create the rectangles by.

Hope this helps,

Christopher

Rick Wannall wrote:
If there's any way of knowing ahead of time the maximum number of
rectangles, you might be better off creating all of them ahead of time in
design view. Then hide or reveal them based on your data.

Access is pretty object oriented, but it's not enough so, I think, for you
to be able to create your subform as an object and then create controls as
objects and add them to the collection as you could in flavors of C or VB
these days.

If having them all, and hiding or revealing, is good enough, you would be
able to load up the tag property of each rectangle with values needed to
accomplish the task related to that rectangle. As you click even, use
"=MyClickEvent()".

IN your module (subform, down where the rectangles are) you need a public
function named MyClickEvent. It would refer to Screen.ActiveControl to get
to the clicked rectangle. E.G.:

dim c as control
set c = screen.activecontrol
c.backcolor = vbwhite
if c.tag = "You Win" then
msgbox "Hot dog!"
else
msgbox "Try again"
endif

Would that help you?

By the way, if you're not showing multiple records, why put this in a
subform? There are plenty of other reasons, but if it's okay I'd like to
ask yours.


Jun 2 '06 #6
Of course you're right. I forgot about rectangles. Can you use textboxes
with appropriate back and fore colors instead? Text boxes can receive
focus, whereas rectangles, naturally, cannot.

Sorry about that.

Text boxes should fix you up.
Jun 2 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

53
by: Alf P. Steinbach | last post by:
So, I got the itch to write something more... I apologize for not doing more on the attempted "Correct C++ Tutorial" earlier, but there were reasons. This is an UNFINISHED and RAW document,...
1
by: VB Programmer | last post by:
I had a project called Test1. The url when I test it is http://localhost/Test1 I wanted to totally clone a seperate project called 'Test2'. So I did a project/copy project to Test2. (In other...
4
by: Randall Arnold | last post by:
My application addes or deletes tab pahes at the user's discretion. On each tab page are controls that must be duplicated. Here's a sample of my code: chart_tabcontrol.TabPages.Add(1)...
14
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of...
11
by: jobs239 | last post by:
Can I use this line inside C program "system(java -jar <jarfilename>)" to run a java program from C? Or do I have to use some JNI interface.?
6
by: davetelling | last post by:
I have been using VS-C# Express for a little bit, and I have a project that I want to "clone" so that I can make changes without affecting the original version. I would like to be able to make a...
5
by: Paulo da Silva | last post by:
Hi! I need to process a file to produce another file that *must* have *exactly* the same attributes and permissions of the former. What is the best way to do this? The file must not exist with...
1
by: Bart Simpson | last post by:
Can anyone explain the concept of "slicing" with respect to the "virtual constructor" idiom as explain at parashift ? From parashift: class Shape { public: virtual ~Shape() { } ...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.