473,545 Members | 2,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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 2253
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.ActiveCo ntrol to get
to the clicked rectangle. E.G.:

dim c as control
set c = screen.activeco ntrol
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.ActiveCo ntrol to get
to the clicked rectangle. E.G.:

dim c as control
set c = screen.activeco ntrol
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.ActiveCo ntrol 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.ActiveCo ntrol to get
to the clicked rectangle. E.G.:

dim c as control
set c = screen.activeco ntrol
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
4516
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, and at the end there is even pure mindstorming text left in, but already I think it can be very useful. <url:...
1
1223
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 words, this is a totally new project, not effecting Test1 at all.) When I open Test2 and run the project it goes to http://localhost/Test1 I...
4
1126
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) chart_tabcontrol.SelectedTab = chart_tabcontrol.TabPages(chart_tabcontrol.TabPages.Count - 1) chart_tabcontrol.Refresh() chart_tabcontrol.SelectedTab.Text...
14
2810
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 contents, use the "Bookmarks" tab in Adobe Acrobat. Comments, corrections, praise, nits, etc., are still welcome!
11
2708
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
1701
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 new project, but keep the code & whatever else is necessary from the old project. When I tried this, I got a whole bunch of errors about not being...
5
1514
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 contents (it may exist empty) unless it has the same attributes and permissions. I know how to do this using, let me call it, "C type code" (stat,...
1
3459
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() { } // A virtual destructor
0
7496
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7452
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7784
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6014
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5354
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5071
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3485
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1916
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.