473,785 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

form object persistence...i ncluding contents of controls

1) Module1 has the following delcaration:

Public g_frmZZZ as Form
Public g_txtForm2 as Variant

2) app has two forms: form1 and form2

3) a command button on form1 opens form2; it also has another command
button the purpose of which is to permit one to set a breakpoint in
the code behind the button

DoCmd.Open acForm, "form2"

4) form2 has a text box control: txtForm2

5) form2 has a command button which, when clicked, executes this code:

' save the form into a public variable
Set g_frmZZZ = Me
' save the contents of a control on the form into a public variable
g_txtForm2 = Me.txtForm2
' close this form
DoCmd.Close acForm, "form2", acSavePrompt

If I have a breakpoint set in the code behind the second button in
form1, and I do the following:
step 1: on form1 click command button to open form2
step 2: on form2, type in the letter "q" in the text box control
step 3: on form2, click the command button
step 4: on form 1, click the second command button...go to breakpoint

if I type the following in at the Debug window:
print g_frmZZZ.txtFor m2 <press enter key>

I get run-time error 2467 with a message: "applicatio n-defined or
object-defined error"

if I type the following in at the Debug window:
print g_txtForm2 <press enter key>

it prints the letter "q" in the debug window.

If I comment out the DoCmd.Close line in the code behind the command
button in form2, and repeat the same steps, then if I type the
following in at the Debug window:
print g_frmZZZ.txtFor m2 <press enter key>

it prints the letter "q" in the debug window.

I was thinking that by declaring g_frmZZZ as public and then setting
g_frmZZZ to form2 just before form2 is closed, it would have the
effect of taking a copy of form2 and putting it into g_frmZZZ. Based
on the tests I ran, it appears as though I was wrong about the whole
"make a copy of..." thing. In the second test (where I don't close
form2), I can interrogate the contents of a control on g_frmZZZ, but
if I close form2 (like I did in the first test) it doesn't know about
the txtForm2 control on g_frmZZZ.

Question 1:
So, if I'm interested in having the contents of the controls on a form
persist, are my two options:
a) keep the form open for as long as the app needs to interrogate the
contents of the controls
b) set up a public data structure where various elements in the data
structure correspond with controls on the form...then, if one needs to
close the form, run some code that populates that public data
structure with the contents of the control on the form

Question 2:
Is there a way to instantiate a new form object in such a way that:
a) the form gets created/populated (including contents of controls)
as a copy of an already
existing form
b) when the already-existing form gets closed, the just-instantiated
form is NOT affected, i.e. it
retains all the info it received (including contents of controls)
when instantiated

Thank you.

Dec 13 '07 #1
1 2329
Oko
In Relation to preserving form values:

Setting one variable equal to another can be done two ways: "By
Reference" or "By Value". "By Reference" means that you don't create a
copy - but rather point to where the value is in memory. This is not
unlike a library's catalog system telling you where a book is found.

Once the value is erased (or the book is checked out), your reference
to its location is invalid - and you find nothing instead. This seems
to be what's happening to you when your form closes.

"By Value" will actually create the copy of the value that you speak
of. A more stable response on the part of the VB interpreter - but I'm
not sure when it decides which strategy it will use.

What I've done in the past is leave the form open - but set
it's .visible property (it's not listed in the properties window,
gonna hafta trust me on this) to FALSE. This way the form disappears
as if closed and cannot be manipulated by the user - but the
information is still completely accessible.

In Relation to creating a copy of the form:

I am unsure what you are looking to achieve. If I knew this I may be
able to help you better.

mirandacasc...@ yahoo.com wrote:
1) Module1 has the following delcaration:

Public g_frmZZZ as Form
Public g_txtForm2 as Variant

2) app has two forms: form1 and form2

3) a command button on form1 opens form2; it also has another command
button the purpose of which is to permit one to set a breakpoint in
the code behind the button

DoCmd.Open acForm, "form2"

4) form2 has a text box control: txtForm2

5) form2 has a command button which, when clicked, executes this code:

' save the form into a public variable
Set g_frmZZZ = Me
' save the contents of a control on the form into a public variable
g_txtForm2 = Me.txtForm2
' close this form
DoCmd.Close acForm, "form2", acSavePrompt

If I have a breakpoint set in the code behind the second button in
form1, and I do the following:
step 1: on form1 click command button to open form2
step 2: on form2, type in the letter "q" in the text box control
step 3: on form2, click the command button
step 4: on form 1, click the second command button...go to breakpoint

if I type the following in at the Debug window:
print g_frmZZZ.txtFor m2 <press enter key>

I get run-time error 2467 with a message: "applicatio n-defined or
object-defined error"

if I type the following in at the Debug window:
print g_txtForm2 <press enter key>

it prints the letter "q" in the debug window.

If I comment out the DoCmd.Close line in the code behind the command
button in form2, and repeat the same steps, then if I type the
following in at the Debug window:
print g_frmZZZ.txtFor m2 <press enter key>

it prints the letter "q" in the debug window.

I was thinking that by declaring g_frmZZZ as public and then setting
g_frmZZZ to form2 just before form2 is closed, it would have the
effect of taking a copy of form2 and putting it into g_frmZZZ. Based
on the tests I ran, it appears as though I was wrong about the whole
"make a copy of..." thing. In the second test (where I don't close
form2), I can interrogate the contents of a control on g_frmZZZ, but
if I close form2 (like I did in the first test) it doesn't know about
the txtForm2 control on g_frmZZZ.

Question 1:
So, if I'm interested in having the contents of the controls on a form
persist, are my two options:
a) keep the form open for as long as the app needs to interrogate the
contents of the controls
b) set up a public data structure where various elements in the data
structure correspond with controls on the form...then, if one needs to
close the form, run some code that populates that public data
structure with the contents of the control on the form

Question 2:
Is there a way to instantiate a new form object in such a way that:
a) the form gets created/populated (including contents of controls)
as a copy of an already
existing form
b) when the already-existing form gets closed, the just-instantiated
form is NOT affected, i.e. it
retains all the info it received (including contents of controls)
when instantiated

Thank you.
Dec 13 '07 #2

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

Similar topics

2
3089
by: Citoyen du Monde | last post by:
Trying to get some ideas on a simple javascript project (to teach myself the language). I want to develop a client-side vocabulary practice application that would allow users to enter their own words, their own definitions plus an example of how the word is used in practice. It'll be all client side with - cookies? to get persistence so that the words won't disappear on me each time the page is closed (which is what happened when I
7
3562
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET) template. Briefly -------------------------------------------------------------------------------------------- I need to create dynamically some controls on the forms, and display these
3
14164
by: Chris | last post by:
Hi, I'm trying to append text from another class to a generic richTextBox that I've added to a Windows form. I can't seem to figure out how to expose the richTextBox to append text to it. Thanks in advance, Chris
2
8312
by: Jaikumar | last post by:
Hi, 1) I have created one windows application, In the main form ( form1) i have added one usercontrol (usercontrol1), In that user control i am drawing one image. 2) In the UserControl1 i am showing one transparent form (form3) when ever user preseed left mouse button. 3) The form3 has one transparent user control (usercontrol2) that paints circles. That measn the circles will show on top the usercontrol1 image. 4) The form3 border style...
25
4073
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
8
3713
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box and save it to a file. This step is not to hard however the contents of the textarea is mostly latex source so it contains just about every special character you can imagine. My question is this, how do I save an exact copy of the textarea...
6
2434
by: ahmad.humyn | last post by:
I want to call a hidden form. My code goes something like in which the main calls form1. form1 has a button which creates & calls form2 and hides itself. Now I have a button in form2 which if pressed should dispose form2 and then unhide and focus form1. -------------------------------------------------- static void Main() { ..... Application.Run(new Form1());
2
59199
NeoPa
by: NeoPa | last post by:
CHAPTER 1 - TABLE OF CONTENTS (Including attached database) CHAPTER 2 - INTRODUCTION CHAPTER 3 - TABLE LAYOUT CHAPTER 4 - FORM LAYOUT CHAPTER 5 - FORM MODULE CHAPTER 6 - CODE DISCUSSION (FILTER CONTROLS) CHAPTER 7 - CODE DISCUSSION (THE REST) --------------------------------------------------------------------------------
5
2531
by: lukasmazur | last post by:
Hi I have a problem with using listBox1. I have a two forms form1 and form2. In form1 are controls listBox1, textBox1 and button witch creating object of class Form2. In class Form2 I create a pointer to object of class Form1. I don't known how to use method add(), where can I find it. From Form1 I can add value like this this->listBox1- I cant find it. I have textBox1 on Form1 and I can change text in this control like this ...
0
9645
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10090
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9949
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6739
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.