 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 15th, 2005, 10:18 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Can't find subform referred to in VBA Error 2450
Okay, I know someone knows this:
I have a module that picks the record PK from a subform, and then works through some queries and totals some dollar amounts, and then returns the total to the subform line, one for each record.
So for example, I have a Project table (main form) and each project can have sub projects (sub form) and each sub project can have itemized labor expenses (sub sub form that opens seperately.) The user enters itemized labor to the sub sub form, and then closes it. The sub form is supposed to then total the itemized labor expenses for each sub project individually. (text box with "=Labor()" module function as control source)
When I open the subform by itself, the module works fine and reports the proper total itemized labor expenses for each sub project.
However, when I open the main form that contains the sub form, I get this error:
"Run-time error '2450':
Microsoft Access can't find the form 'sfrmProjDetail' referred to in a macro expression or Visual Basic code."
I know this should be simple but can't figure out what to do.
Thanks,
mmcdonal
__________________
mmcdonal
Look it up at: http://wrox.books24x7.com
|
|

April 15th, 2005, 02:13 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
I believe that no reference to the subform will work until the subformâs initialization has reached a certain point. At the time you are trying to refer to it, it is not yet open for business.
Perhaps you could put a delay in your error handler, and a counter. When the error hits, check the counter value, and if not too many, increment it, run the delay, then Resume.
Perhaps you could put a loop above the point that offends (with on error resume next inside it), continuing to loop till an amount of time has expired, or the subform has become ready to be reasonable (make a reference to it, see if that causes an error; if so, loop).
Brian
|
|

April 18th, 2005, 10:05 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I tried practically every event on the sub form, and I think the issue is that if you put the timer on, then it waits for the timer to run and the event to finish until it moves on to the next event, so this is not working.
I also read in Alison Balter that you can set the subform control values from the main form, not the subform. This doesn't work either, but the problem is here that if I set the control source of my text box from the main form, like this: Forms!sfrmMySubForm!txtMyTextBox!ControlSource = "=MyFunction()" then I am essentially editing the sub form in design view, and I am asked to save my changes when I close the main form. I would also have to change the control source of the text box back to "" when I closed the main form so that I wouldn't get the original error the next time I opened the main form.
Anyway, I am thinking I could make a hidden form that opens when the main form opens, waits a few seconds, and then changes the control source for the text box on the sub form. Then I could have the hidden form change the control source back to nothing on the close event of the main form. I still have the "save changes" dialog problem this way, though.
I also tried putting a timer in the function, but that didn't work either.
Any more help? Come on people. :)
mmcdonal
|
|
 |