Solved Error 2445 when formatting a text box

zelarra821

Registered User.
Local time
Today, 05:36
Joined
Jan 14, 2019
Messages
850
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:
In a module
 
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:
try:
Code:
Forms![FPresupuestos]![FPresupuestosSubformulario].Form.TxtQuantityAProrratear.BackColor
 
for single Record subform, it will work.
it won't work on datasheet/continuous subform.
you need to use CF for those two.
 
It is for a continuous form. If I pass it to the subform, won't it work either?
 
Code:
Me![FPresupuestos].Form!TxtQuantityAProrratear.BackColor = vbRed
From a button on the mainform, to a continuous form
 
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
 
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.
 
it won't work, in the sense that it will change the backcolor of all rows
on the same field/textbox.
 
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.
 
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.
 
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!
 
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.
 
Well then I know where the fault comes from. Thank you very much.
 
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.
 
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.
 
@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

Back
Top Bottom