Referencing Forms

Funger

Registered User.
Local time
Today, 08:02
Joined
Jan 16, 2004
Messages
18
Easy Question, I hope. refrencing forms

I know in VBA that you can refrence a form like so:

public sub test()
....Dim frm as Form
....Dim ctl as Control

....set frm = forms("frmParent")
....for each ctl in frm.Controls
........msgbox(ctl.Name)
....next ctl
end sub

My question, is how do I set the frm object to a subform of a form? if frmParent had a subform object on it called frmChild, how could I set the frm object to that form?

The overall problem is that I am having problems with Access XP with objects that have recordsources with refrences to controls on the form. When the form closes, I get parameter value errors. My solution to this was to set all of the recordsource properties on the form to "" on the close event.
This seems to work, however if there is a subform with said situation, I can't fix it, and I would like to make a catchall sub that can handle any form. If I can figure out how to refrence the subforms, then I can make a nice little recursive function to handle any form.

Thanks for any assistance!

-Jim
 
how do I set the frm object to a subform of a form?
Use the format:
Forms("mainform")("subform")
to refer to the subform itself

Use
Forms("mainform")("subform")("control")
to refer to a control on the subform.

When the form closes, I get parameter value errors.
Can you be more specific? Do you get an error code? Message?
 
Sure.


error.jpg


I get this error when closing the form "frmMnt_Student"

chkLimitStudentList is a checkbox on that form.
And a dropdown box that refrences that checkbox in it's rowsource property had the focus while the form was being closed.


-Jim
 
You cannot reference a form's controls if that form is not open. Either leave the form open or change your queries to get their criteria some other way.
 
:) I know you must have a form open in order to reference the controls.

This error happens when I am closing a form. On this form is both the control that is being referenced and the control that is referencing it.
 
I have many situations where I use combo's who's rowsource queries reference form fields from the open form. These cause no problems when the form is closed. I don't know what you mean by
objects that have recordsources with refrences to controls on the form
. Are you saying that you have unbound controls in the subform and they are referencing controls on the mainform? The main form closes first, is that what your problem is?
 
Nope. It's a bug that happens in XP, but never happened for me in 2000... Although it's also happened when using the database with the access 2000 runtimes.

On the form are three controls. (shown below)
Controls.jpg


The Dropdown on the left has the rowsource shown below:
Rowsource.jpg


When the dropdown on the left has a data in it, and the form is closed, I get the parameter value error shown below.
Error.jpg


Its a strange error.

-Funger
 
Sorry, I don't see the problem. You might try posting the db. Perhaps someone will be able to figure it out.
 

Users who are viewing this thread

Back
Top Bottom