Problem reading info from a form's property

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 07:05
Joined
Jul 9, 2003
Messages
17,503
In answering a question I ran a little test first, which involved extracting the text from a forms Tag property.

I created a temporary form added a command button and added the following code to the command button:

MsgBox " >>> " & Form_frmAddress.Tag

but it didn't work! I got an error, and on investigation I found that there was no code behind the form "frmAddress". Subsequently I added only a comment to the form "frmAddress" code module and tried my command button again and it worked extract in the tag!

I didn't realize that you could not access a forms properties if there was no code behind?

Something I will definitely have to watch out for....
 
In answering a question I ran a little test first, which involved extracting the text from a forms Tag property.

I created a temporary form added a command button and added the following code to the command button:

MsgBox " >>> " & Form_frmAddress.Tag

but it didn't work! I got an error, and on investigation I found that there was no code behind the form "frmAddress". Subsequently I added only a comment to the form "frmAddress" code module and tried my command button again and it worked extract in the tag!

I didn't realize that you could not access a forms properties if there was no code behind?

Something I will definitely have to watch out for....
Hey Giz - I think you are slightly off here due to a few things.

1. You do not need code on a form to access the properties of it.

2. You DO neet to have the form OPENED in order to access them.

3. Your Form_frmAddress.Tag could have had problems because, if that is its real name then the Form_ part can confuse and disorient Access.


I just ran a test also, which I created a form (Form2) and put a text box on it (Text0) and put the words TestTag into it. I opened Form1 and put a command button on it. In its click event I put
MsgBox Forms!Form2.Text0.Tag
and it didn't work, but I didn't have Form2 open.

I opened Form2 and then clicked the command button on Form1 and it gave me a message box with TestTag as the message.
 
Bob, you're right about having a form open in order to access its properties.

However, if I understood my studies correctly, one could access forms' properties, regardless if it's closed or open if you used the CurrentProject model. Hmm... maybe should test for that. I dont have the book with me, so will consult it tomorrow to get the syntaxes for doing so and report back with the test.
 
Bob, you're right about having a form open in order to access its properties.

However, if I understood my studies correctly, one could access forms' properties, regardless if it's closed or open if you used the CurrentProject model. Hmm... maybe should test for that. I dont have the book with me, so will consult it tomorrow to get the syntaxes for doing so and report back with the test.

Sounds good - let us know your findings.
 
Hi gizmo,

If the Form's property "Has Module" is set to "No", you not be able to access it's property. This setting is automatic, that is, when ever you key in a line of code, it will automatically set the property to "Yes".

If you have any code behind the Form's module and by changing it to "No", a warning message will pop up about it. If "Yes", you delete whatever code you have on that form.

If your form does not have any code or "Has Module = No", the form name will not appear in your editor Intellisense drop down.

In answering a question I ran a little test first, which involved extracting the text from a forms Tag property.

I created a temporary form added a command button and added the following code to the command button:

MsgBox " >>> " & Form_frmAddress.Tag

but it didn't work! I got an error, and on investigation I found that there was no code behind the form "frmAddress". Subsequently I added only a comment to the form "frmAddress" code module and tried my command button again and it worked extract in the tag!

I didn't realize that you could not access a forms properties if there was no code behind?

Something I will definitely have to watch out for....
 
Thank you all for your interesting observations on this conundrum, it will be Interesting to see if it's possible with the CurrentProject model. I have done a couple of experiments myself, but cannot seem to get the syntax right, however one interesting thing did arise, prefixing the code with "CurrentProject" kicked it into the local MS Access error reporting (I guess) which gives me an idea for solving a problem In another database.
 
Hi gizmo,

If the Form's property "Has Module" is set to "No", you not be able to access it's property. This setting is automatic, that is, when ever you key in a line of code, it will automatically set the property to "Yes".
Not true, sorry.
 
Okay, had a good look at the Currentproject model.

Few things I've concluded:

1) You could use Allforms collections to give you a list of all forms in database, whether it's loaded or not. You could then use that collections to programmically load a form and alter the properties if needed.

2) The CurrentProject is pretty much read-only.

3) Bizarrely, members of the Allforms collections are not Forms, but "AccessObject". AccessObject is more generic in that it describes an object, be it form, report, macro, whatever. Because it's not same thing as Form, you can't use AccessObject's properties collection to access the form's properties. I'm kind of stumped why Microsoft decided to refer to AccessObject, which incidentally has a Type property that tells what kind of AccessObject it is and therefore should theoretically be able to enumerate the all properties of a form if it represents a Form.

Maybe someone will know what to do with it, but I've concluded that it's more work to monkey with Currentproject model and that #1 is more straightforward way of altering a form's properties when it's not currently open.
 
Hi Bob,

Rather than to say "Not true", Have you created a sample of a blank Form?

I have created a blank form, no controls, nothing at all. Just save the form as "Form1" or what ever. Before you closed the form, note of the form's properties "Has Module" it is by default set to "No".

Do not open this form again to enter any code. Open another existing form or a new form, click the Code icon to access the VB editor. Right click any where in the blank area, A list appears, select "List Properties/Methods". Try to look for the previous form that you have saved. It will not be there ("Form1").

Not true, sorry.
 
Hi Bob,

Rather than to say "Not true", Have you created a sample of a blank Form?

I have created a blank form, no controls, nothing at all. Just save the form as "Form1" or what ever. Before you closed the form, note of the form's properties "Has Module" it is by default set to "No".

Do not open this form again to enter any code. Open another existing form or a new form, click the Code icon to access the VB editor. Right click any where in the blank area, A list appears, select "List Properties/Methods". Try to look for the previous form that you have saved. It will not be there ("Form1").

I think you misunderstand the difference between being able to access the form/form's controls PROPERTIES as compared to the VBA IDE Window not showing the form in the list for the events. You can access the form's PROPERTIES via code as long as the form is open EVEN IF THE FORM HAS NO MODULE. I didn't say you would access it from THAT form's module.
 
Well Bob,.....perhaps we are in a different brain wave length.

Yes, your right. You still can access to the form's properties.

It's just maybe we need to define/create the object first before changing the object value just like the Table Description property. The object is there in the table but you can't via code to edit the value, you'll have create a field description first than insert the value by DAO. It was never possible by ADO method.

I think you misunderstand the difference between being able to access the form/form's controls PROPERTIES as compared to the VBA IDE Window not showing the form in the list for the events. You can access the form's PROPERTIES via code as long as the form is open EVEN IF THE FORM HAS NO MODULE. I didn't say you would access it from THAT form's module.
 
I note the following in the book:

Beginning Access 97 VBA Programming by David Sussman and Rob Smith

On page 390, (it's about using instances of the form)

Extract:
The first thing we do is create a variable of type Form_BottlingDetails. As was mentioned above, if there is any code behind a form, or if there is no code, but you have explicitly set the "has module property" of the form to true, then the form is saved as a class module and we can create an object variable based on that class. (the corollary is that if there is no code behind the form, and you have not set the "has module property" of the form, true, there will be no class module so you will not be able to create multiple instances of the form)

So I take it that you don't necessarily need to add any code or comments to the code behind a form, you just have to make sure that the "has Module property" is set to true.

I wonder if you can do this from code?
 

Users who are viewing this thread

Back
Top Bottom