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.
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.
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.
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.
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..
First and foremost you are challenging our patience by ignoring questions and comments and instead reiterating vague statements that most likely are incorrect.
I've been setting Datasheet Forms Record source to a query then each fields control source via the dropdown in Properties - Data Tab. Now I'm wondering if instead you can set Form record souce to the actual sql string insted of the query name, and not need the query. But then the control...
@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.
There is often a lot of confusion about Access Events and often answering questions posed here is difficult because of inaccurate terminology. People often say "Event" when it is unclear if they mean the actual event that takes place, the event procedure, or the event property. This thread...
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
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
Here's a little puzzle for anyone interested. It is based on a similar item posted at the DBGuy's website 3 years ago which he was unable to explain. As I like riddles(!) I worked out how it was done and am posting a modified version here with his permission. The attached database contains...
Must say I've never seen this happen before, but : I've a combo box set up with a Value List ('Row Soiurce Type : 'Value List') on a Form, and until today it was working well; no problems. Today, for some unknown reason, the 'Row Source' ellipsis has disappeared. ('Data' tab > 'Row Source')...
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.
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
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.
There is often a lot of confusion about Access Events and often answering questions posed here is difficult because of inaccurate terminology. People often say "Event" when it is unclear if they mean the actual event that takes place, the event procedure, or the event property. This thread...
www.access-programmers.co.uk
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
Here's a little puzzle for anyone interested. It is based on a similar item posted at the DBGuy's website 3 years ago which he was unable to explain. As I like riddles(!) I worked out how it was done and am posting a modified version here with his permission. The attached database contains...
Must say I've never seen this happen before, but : I've a combo box set up with a Value List ('Row Soiurce Type : 'Value List') on a Form, and until today it was working well; no problems. Today, for some unknown reason, the 'Row Source' ellipsis has disappeared. ('Data' tab > 'Row Source')...
@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.
There is often a lot of confusion about Access Events and often answering questions posed here is difficult because of inaccurate terminology. People often say "Event" when it is unclear if they mean the actual event that takes place, the event procedure, or the event property. This thread...
www.access-programmers.co.uk
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
Here's a little puzzle for anyone interested. It is based on a similar item posted at the DBGuy's website 3 years ago which he was unable to explain. As I like riddles(!) I worked out how it was done and am posting a modified version here with his permission. The attached database contains...
Must say I've never seen this happen before, but : I've a combo box set up with a Value List ('Row Soiurce Type : 'Value List') on a Form, and until today it was working well; no problems. Today, for some unknown reason, the 'Row Source' ellipsis has disappeared. ('Data' tab > 'Row Source')...
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.
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..
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.
Hi everyone, I have the code to create multiple instances of a form, maximum of 12. I would like these 12 forms to be temporary rename so I can use the "DoCmd.MoveSize" command to show each one of them to a particular place on the screen. When the user is done, delete the forms. So the name I...
What happens if you were to open the same form multiple times? passing a CustID for instance as OpenArgs? instead of a WHERE clause? Not sure what you mean by this. If you are referring to multiple form instances (the same form opened multiple times at once) then openargs cannot be used. You...
www.access-programmers.co.uk
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.
How to open more than one instance of a form at once in a Microsoft Access database, and manage the instances independently of each other.
allenbrowne.com
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.
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).
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.
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.