Solved it's Magic you can store data in a closed unbound form! (1 Viewer)

MsAccessNL

Member
Local time
Today, 11:42
Joined
Aug 27, 2022
Messages
185
I think it's because a form is also a class. When you declare a Form event (can be without code), the form class is initialized and the form controls can be handled, even when the form is closed, the class is activated by calling the form control.
 

sonic8

AWF VIP
Local time
Today, 11:42
Joined
Oct 27, 2015
Messages
1,001
When you declare a Form event (can be without code), the form class is initialized and the form controls can be handled, even when the form is closed, the class is activated by calling the form control.
What do you mean by "declare a Form event" and what by "calling the form control"? - These statement make no sense to me in this context.

Anyway, if you create an instance of a form class the form is not closed anymore.
 

Minty

AWF VIP
Local time
Today, 10:42
Joined
Jul 26, 2013
Messages
10,380
This behaviour is known. You can instantiate an instance of a form, but it isn't visible.
I can't remember the exact syntax required but it has been discussed within the forum walls before.
 

MsAccessNL

Member
Local time
Today, 11:42
Joined
Aug 27, 2022
Messages
185
I know you want to know the answer, I am giving a hint for the solution. I am telling you that it's possible to save and restore data from a closed Form. You can retrieve the data anywhere like with a Public variable. I am challenging you to solve this puzzle? But I understand if you don't like to do so.
 

MsAccessNL

Member
Local time
Today, 11:42
Joined
Aug 27, 2022
Messages
185
This behaviour is known. You can instantiate an instance of a form, but it isn't visible.
I can't remember the exact syntax required but it has been discussed within the forum walls before.
Did you know that you can address a form control directly in this way. Instead of a long reference like Forms!FormX.SubFormContainer.Form.txtControl . You can skip all the hassle, and you get intellisense, i think it's pretty amazing..
 

sonic8

AWF VIP
Local time
Today, 11:42
Joined
Oct 27, 2015
Messages
1,001
I am challenging you to solve this puzzle?
First and foremost you are challenging our patience by ignoring questions and comments and instead reiterating vague statements that most likely are incorrect.
 

moke123

AWF VIP
Local time
Today, 05:42
Joined
Jan 11, 2013
Messages
3,964
I can't remember the exact syntax required but it has been discussed within the forum walls before.
you mean like
Code:
Set m_objfrmDP = New Form_pfrmNDP
 

Minty

AWF VIP
Local time
Today, 10:42
Joined
Jul 26, 2013
Messages
10,380
It was discussed here:
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:42
Joined
May 21, 2018
Messages
8,655
@MsAccessNL
It is pretty hard to take-on a this challenge since as pointed out by @sonic8 you are using in imprecise and meaningless language. I understand that maybe some of this is lost in translation from Dutch to english, but it makes it hard to know what you mean.
When you declare a Form event
Never heard of "declaring an event". You can define a custom event
Code:
Public Event SomeEvent
If you want to learn about precise language about events read this. I wrote this because there is often a lot of poor terminology here when people talk about events, event handlers, event procedures.

the class is activated
I googled this to see if this terminology is use in other OOP languages. You can "instantiate' an object of a class. You can "declare" a class variable, but never heard the term "activate a class". The term "activate" is used in Access to refer to an object such as a form receiving the focus. See
form controls can be handled
Not sure what that means. I assume that means that the "Events raised by a control can be handled"

Bottom line is you are incorrect and the following is not true.
I am telling you that it's possible to save and restore data from a closed Form.
The only thing I can guess is that you think it is closed, but it is not.
You cannot instantiate a form's class without also opening the form!!!
If you are referring to
Code:
Dim myFrm as Form_FrmCustomers
set myFrm = New Form_FrmCustomers

The above syntax creates an instance of the form customers and sets it visible property to false. So it is Open not Closed.

Since you cannot properly describe the challenge, maybe post some code and we can see what you mean.
@isladogs posts some really good well articulated challenges on this forum. Most have to do with security. Here is one

This helped to answer the below thread
 

moke123

AWF VIP
Local time
Today, 05:42
Joined
Jan 11, 2013
Messages
3,964
Examples please?
The only thing I could think of, that would not go out of scope when closing the database, is to append something to the database properties collection. Not that I would do it but you technically could.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:42
Joined
May 21, 2018
Messages
8,655
If you want to see "Magic" or at least another good Access Puzzle see this on how Setting the rowsource of a listbox to "" or setting the recordset to nothing does not clear the listbox.
 

MsAccessNL

Member
Local time
Today, 11:42
Joined
Aug 27, 2022
Messages
185
@MsAccessNL
It is pretty hard to take-on a this challenge since as pointed out by @sonic8 you are using in imprecise and meaningless language. I understand that maybe some of this is lost in translation from Dutch to english, but it makes it hard to know what you mean.

Never heard of "declaring an event". You can define a custom event
Code:
Public Event SomeEvent
If you want to learn about precise language about events read this. I wrote this because there is often a lot of poor terminology here when people talk about events, event handlers, event procedures.


I googled this to see if this terminology is use in other OOP languages. You can "instantiate' an object of a class. You can "declare" a class variable, but never heard the term "activate a class". The term "activate" is used in Access to refer to an object such as a form receiving the focus. See

Not sure what that means. I assume that means that the "Events raised by a control can be handled"

Bottom line is you are incorrect and the following is not true.

The only thing I can guess is that you think it is closed, but it is not.
You cannot instantiate a form's class without also opening the form!!!
If you are referring to
Code:
Dim myFrm as Form_FrmCustomers
set myFrm = New Form_FrmCustomers

The above syntax creates an instance of the form customers and sets it visible property to false. So it is Open not Closed.

Since you cannot properly describe the challenge, maybe post some code and we can see what you mean.
@isladogs posts some really good well articulated challenges on this forum. Most have to do with security. Here is one

This helped to answer the below thread
Oke
@MsAccessNL
It is pretty hard to take-on a this challenge since as pointed out by @sonic8 you are using in imprecise and meaningless language. I understand that maybe some of this is lost in translation from Dutch to english, but it makes it hard to know what you mean.

Never heard of "declaring an event". You can define a custom event
Code:
Public Event SomeEvent
If you want to learn about precise language about events read this. I wrote this because there is often a lot of poor terminology here when people talk about events, event handlers, event procedures.


I googled this to see if this terminology is use in other OOP languages. You can "instantiate' an object of a class. You can "declare" a class variable, but never heard the term "activate a class". The term "activate" is used in Access to refer to an object such as a form receiving the focus. See

Not sure what that means. I assume that means that the "Events raised by a control can be handled"

Bottom line is you are incorrect and the following is not true.

The only thing I can guess is that you think it is closed, but it is not.
You cannot instantiate a form's class without also opening the form!!!
If you are referring to
Code:
Dim myFrm as Form_FrmCustomers
set myFrm = New Form_FrmCustomers

The above syntax creates an instance of the form customers and sets it visible property to false. So it is Open not Closed.

Since you cannot properly describe the challenge, maybe post some code and we can see what you mean.
@isladogs posts some really good well articulated challenges on this forum. Most have to do with security. Here is one

This helped to answer the below thread
Thank you for the information. The hidden form is the possible answer. The strange thing is that if, I only Put: Form_F_Test_txtTest = “Hallo” into the immediate window, this statement alone opens a hidden form. So if you would make a bound form, the value Form_Public.Firstname could be used everywhere like a public variable and would probably hold his value even after closing or with an error in the vba code.

Ps I started my post with “I think..” meaning that i am not sure what is going on, but i am willingly to learn.
 
Last edited:

MsAccessNL

Member
Local time
Today, 11:42
Joined
Aug 27, 2022
Messages
185
Solution thanks to MajP, who is much more experienced then I am. If you type Form_FormName.TxtTest = "Hallo" into the immediate window, this will open (apearantly) a Hidden instance of the form. When you open the form from the nav pane, another instance (..may be not the correct word, don't kill me please..) of the form is opened. Type Form_FormName.visible = True and you will see two times the same form. Like with a real magician, the magic wasn't realy magic. I still think you can use this to store Public variables, with a bound form they will be still there after closing the database. But i didn't test this yet..
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:42
Joined
May 21, 2018
Messages
8,655
FYI. The reason why I was nit picking on this is that you can do exactly what you describe in other applications but not in Access. It would be great if you could and solve and make a lot of things easier.
In Visual Studio for example you can do something like this (pseudo code) and set properties of the form before opening the form:

Dim frm as New FormName ' will not open an instance of the form but creates an instance of the form class
frm.SomeProperty = "Something"
frm.SomeOtherProperty = "Something Else"
frm.Open 'Opens the form with the properties set


Someone smarter than me will have to explain the difference between instantiating the instance of the form and opening the form
In Access you cannot do this seperately. In VB.NET you can.

This would be great if you could. We are left with OpenArgs as a kind of workaround.
Some may argue you can open the form hidden, modify the properties, then show it. That is different and may or may not work. Setting the properties before opening will not cause any events to occur. If you have events in the open or load they occur even if hidden.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:42
Joined
May 21, 2018
Messages
8,655
May find this interesting as it relates to multiple form instances and demos some of these properties.


If you are working with multiple form instances you need a means to manage them. They all share the same name so they cannot be managed in the normal Forms Collection. You need a custom collection.

You can view the thread posted by @Minty to get some understanding on the nature of form instances. You have to wade through some serious incorrect made up information posted by other members of this forum though.
 

sonic8

AWF VIP
Local time
Today, 11:42
Joined
Oct 27, 2015
Messages
1,001
frm.Open 'Opens the form with the properties set


Someone smarter than me will have to explain the difference between instantiating the instance of the form and opening the form
In Access you cannot do this seperately. In VB.NET you can.
I noted you marking your code as "pseudo code". Nonetheless, I need to nitpick because it is at the very heart of the matter: There is no Open method for a Windows.Forms.Form class!
I guess you mean the Show method. However, as per documentation, this method does nothing other than setting Visible=True. So this is very much like the behavior of an Access.Form.

The significant difference is the the ShowDialog method. If you call this method, the Windows.Forms.Form class will destroy the already created Win32-Window of the form and create a new one with the dialog flags of the Window set. - This option is the major difference between an Access.Form, where this is not possible, and a Windows.Forms.Form.

So the difference between instantiating a form class and opening a form is that the latter requires a Win32-Window to be created while the former does not (depending on implementation, it still may do it regardless).
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:42
Joined
Feb 19, 2002
Messages
43,603
@MsAccessNL
Not sure what your point is BUT

TABLES store data. FORMS do not store data. Just because you might be able to manipulate a form this way is irrelevant. Forms exist in the FE database of the application. They are not shared with other users AND the FE is totally replaced whenever the developer makes FE changes so even if you managed to make some value persist between one opening of the FE and another. It could be gone tomorrow.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 05:42
Joined
May 21, 2018
Messages
8,655
I noted you marking your code as "pseudo code". Nonetheless, I need to nitpick because it is at the very heart of the matter: There is no Open method for a Windows.Forms.Form class!
Yes I probably should have been more specific but I unfortunately thought too much information would confuse the issue, so I kept the idea as pseudo code. But yes showdialog it what I was referring. I often have a parameterized contructors and then want to return values when the form is closed
Something like

so in my calling form something like
Code:
    Public Sub New(ByVal CurrentName As String, ByVal AvailableVars As LP_VariableCollection)
        InitializeComponent()
        _CurrentName = CurrentName
        _NewName = CurrentName
        _LPVars = AvailableVars
    End Sub

And then to call it and return the values.
Code:
    Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
        Dim frm As New frmEditVariableName(getMaxXi, _LPVars)
        frm.ShowDialog()
        If Not frm.DialogResult = vbCancel Then
            addVariable(frm.NewName)
        End If
        frm.Dispose()
    End Sub
So if I understand correctly creating the window and instantiation of the class are two discrete things.
 

Users who are viewing this thread

Top Bottom