473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

form object persistence...including 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.txtForm2 <press enter key>

I get run-time error 2467 with a message: "application-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.txtForm2 <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 2300
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.txtForm2 <press enter key>

I get run-time error 2467 with a message: "application-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.txtForm2 <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
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...
7
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)...
3
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. ...
2
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...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
8
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...
6
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...
2
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...
5
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.