Solved Error 2445 when formatting a text box (1 Viewer)

zelarra821

Registered User.
Local time
Today, 04:12
Joined
Jan 14, 2019
Messages
809
Good Morning. I have a problem that I think is syntax. I'm getting an error 2455, which says you have specified an expression that contains an invalid reference to the Form / Report property.

The line where it gives the error is this:

Code:
         Forms! [FPresupuestos]! [FPresupuestosSubformulario] .Form! TxtQuantityAProrratear.BackColor = RGB (ColorFondoRed, ColorFondoGreen, ColorFondoBlue)

What am I doing wrong?

Thank you.
 
Last edited:

zelarra821

Registered User.
Local time
Today, 04:12
Joined
Jan 14, 2019
Messages
809
In a module
 

Minty

AWF VIP
Local time
Today, 03:12
Joined
Jul 26, 2013
Messages
10,368
Can I ask why - it is obviously very specific to the form, so why not simply run it from the form?
Then you would be able to refer to the controls directly.

Putting things in modules can be great, but when something is unlikely to be reused anywhere else it makes no sense to me.
Keep it with the form it's updating.

I would suspect you have a spelling error in your form reference. Double-check it, or use the expression builder to build it for you, then cut and paste.
 
Last edited:

Rene vK

Member
Local time
Today, 04:12
Joined
Mar 3, 2013
Messages
123
try:
Code:
Forms![FPresupuestos]![FPresupuestosSubformulario].Form.TxtQuantityAProrratear.BackColor
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:12
Joined
May 7, 2009
Messages
19,229
for single Record subform, it will work.
it won't work on datasheet/continuous subform.
you need to use CF for those two.
 

zelarra821

Registered User.
Local time
Today, 04:12
Joined
Jan 14, 2019
Messages
809
It is for a continuous form. If I pass it to the subform, won't it work either?
 

Rene vK

Member
Local time
Today, 04:12
Joined
Mar 3, 2013
Messages
123
Code:
Me![FPresupuestos].Form!TxtQuantityAProrratear.BackColor = vbRed
From a button on the mainform, to a continuous form
 

zelarra821

Registered User.
Local time
Today, 04:12
Joined
Jan 14, 2019
Messages
809
Let's see, this code is applied when it passes registration in the main form, so that the color of that text box of the subform changes
 

Rene vK

Member
Local time
Today, 04:12
Joined
Mar 3, 2013
Messages
123
Let's see, this code is applied when it passes registration in the main form, so that the color of that text box of the subform changes
I created the button on my mainform, had the Continuous form showing in the subform and clicked my button. It works in my app.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:12
Joined
May 7, 2009
Messages
19,229
it won't work, in the sense that it will change the backcolor of all rows
on the same field/textbox.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:12
Joined
May 21, 2018
Messages
8,525
That is a pretty uncommon error, but happens when the subform returns no records. When the subform returns no records the controls are not loaded and thus this error occurs. If you are doing some filtering there could be a timing issue. Which means you want to add DOEVENTS prior to this code running.
 

zelarra821

Registered User.
Local time
Today, 04:12
Joined
Jan 14, 2019
Messages
809
Wait, maybe it's not a syntax problem. In the form, I have a question to create a new record. If I say no, that's when I get the error. So I think the error comes because there are no records. Then it would be a matter of "canceling" that error.
 

zelarra821

Registered User.
Local time
Today, 04:12
Joined
Jan 14, 2019
Messages
809
That is a pretty uncommon error, but happens when the subform returns no records. When the subform returns no records the controls are not loaded and thus this error occurs. If you are doing some filtering there could be a timing issue. Which means you want to add DOEVENTS prior to this code running.
Prize for the Lord!
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:12
Joined
May 21, 2018
Messages
8,525
I can tell you that there are some extremely confusing situations that may cause errors when either a main form or subform returns no records.
A very common one is if you have filter controls in the header and you filter the form based on a control. This normally will cause focus to leave your active control. So any code that references the active control or .text property fails. This one is super confusing because the control you just typed in is not the active control.

If the subform returns no records, the controls are not loaded. But I think the subform is also not loaded. So in this case you cannot reference the control, but it may fail earlier than that by just trying to reference the subform. Untested.
 

zelarra821

Registered User.
Local time
Today, 04:12
Joined
Jan 14, 2019
Messages
809
Well then I know where the fault comes from. Thank you very much.
 

Isaac

Lifelong Learner
Local time
Yesterday, 19:12
Joined
Mar 14, 2017
Messages
8,777
rgb requires numeric values in the parameters you pass in, too.

FYI, if you use Form_Formname, you will get intellisense - and won't make any mistakes about referencing textboxes on forms. Just a tip.
 

zelarra821

Registered User.
Local time
Today, 04:12
Joined
Jan 14, 2019
Messages
809
FYI, if you use Form_Formname, you will get intellisense - and won't make any mistakes about referencing textboxes on forms. Just a tip.
Thanks, but I have no idea how to do what you say.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:12
Joined
May 21, 2018
Messages
8,525
@Isaac,
I would not recommend that anyone without some more context, unless they fully understand the implications of not using it properly. This may cause some hard to understand issues. As shown in that recent thread, the OP showed exactly how not understanding that caused an issue.
The behavior that you pointed out is confusing and is unique to Access AFAIK. Like you said simply by instantiating and referencing an instance of the class it activates an instance in a hidden mode. Since you cannot see it and it goes out of scope no one realizes that behavior. Even in Excel this does not happen you can instantiate an instance of a form class and it does not automatically activate. Same in .NET. So your point of not referencing a form or report by the class is good advice, because of these things that happen that you are unlikely to even realize. You used to see this done a lot for some reason, I have not seen that done for years. In the early days you could not do multiple instances so maybe it made more sense.

In this case it is not applicable anyways since it is a subform. I think it was not called from the main so the OP could not simply
me.[FPresupuestosSubformulario].Form.TxtQuantityAProrratear.BackColor


If you want intellisense as @Isaac is saying, the safe way is you must declare a variable. As @Isaac says this can be very helpful (similar to the discussion on using a module name) because you get intellisense like working directly in the form.

Code:
dim frm as Form_SomeFormName  ' does not instantiate the hidden instance
  set frm = Forms![FPresupuestos]![FPresupuestosSubformulario].Form
  now intellisense
  frm......

In this case you get intellisense and all the form properties, but do not end up automatically activating and referencing a hidden form.
This is likely the reason in Access you almost always open a form from the docmd.

The unsafe way would be (assuming not used as a subform)
Form_FPresupuestosSubformulario.someproperty
That may or may not be referencing the form instance you think.
 

Users who are viewing this thread

Top Bottom