Expression has invalid reference

Spyhunter

Registered User.
Local time
Today, 17:47
Joined
Apr 23, 2010
Messages
86
I have a problem, I opened my database, making changes and closing in Access 2007 at home, I have re-opened in its original Access 2003 (XP) version. I did not ask me to convert but when I attempt some VBA now it states the following error;
Code:
Run-time error 2455:
You entered an expression that has an invalid reference to the property Form/Report

This is the VBA code in question and it worked before;
Code:
JanH = [Forms]![Main]![MainSub1Jan]![TotalHoliday]

Any help would be appreciated as I have come to a dead end.
 
That code doesn't look like what is throwing the error. Does it actually highlight that line or this your suspect?

Also make sure that MainSub1Jan is the name of the subform control, not the name of the form that is embedded in the subform control.
 
the subform is correctly named and the line is highlighted in the VBA window as the error.
 
the weird thing is, i link to it from another area in VBA and it works fine :)
 
Might be worth double-checking your VBA references if you have been opening it in more than one version of Access.
 
Okay, remember subforms have different syntax. You need to make sure that if you use the code you are using that the subform CONTROL ( control on the main form which houses the subform) is named EXACTLY the SAME as the subform. If they aren't then you need to refer to the subform control name and not the subform name (actually in all cases you are referring to the subform control name but it is okay if it is named the same as the subform and it can actually simplify things).

Also, if the subform control name is different then you also need to include the .Form. part in the code. I use it all of the time just to be explicit but if the names are shared then I believe you don't have to use it.

For VBA Code it would be:

JanH = Forms!Main.MainSub1Jan.Form.TotalHoliday
 
Perhaps we can have a look at your db?

Also, if the subform control name is different then you also need to include the .Form. part in the code. I use it all of the time just to be explicit but if the names are shared then I believe you don't have to use it.

For VBA Code it would be:

JanH = Forms!Main.MainSub1Jan.Form.TotalHoliday
It should work without .Form in any scenario but like Bob, it's always better to explicitly reference.
 
Perhaps we can have a look at your db?

It should work without .Form in any scenario

That isn't true. There are times where it is required. I've had it error out unless i used it and normally that has to do with when you have a subform control name different from the subform and then you are trying to set a control value, a property or a method, because Access will tell you that a property or method is not valid when it is but it isn't valid because the subform control doesn't have that value.

Our great Pat Hartman (the second highest poster on this forum) was the one who taught me that through one of her posts. The simple explanation was - that the .Form was needed to let Access know you wanted something on the form and not the subform control which also has properties and methods.
 
Just tested it Bob and it works. Access 2007 by the way. Perhaps I should post an example.
 
Just tested it Bob and it works. Access 2007 by the way. Perhaps I should post an example.

It may work with this particular issue. HOWEVER - there are times it does not and therefore, for CONSISTENT code, I always use it.
 

Users who are viewing this thread

Back
Top Bottom