Passing Subform as Variable

CJBIRKIN

Drink!
Local time
Today, 22:49
Joined
May 10, 2002
Messages
256
Hi


I have an unbound subform whose sourceobject changes. I need to pass the subform as a variable to a module. To complicate matters slightly i have a main form with an unbound subform as well.

Forms!FRM_FRAMES!FRAME_2
main form and unbound subform

Frame_2 then takes the form with the unbound subform.

Forms!FRM_STAFF_DETAILS!FRAME_3 subform



so i think that it should be something like

Forms!FRM_FRAMES!FRAME_2.forms!FRAME_3

With FRAME_3 being the form that i want to use in my function.


If the sourceobject in FRAME_3 is FRM_LEAVE

I can do the following

CountRecordsDisplay Form_FRM_LEAVE

and that works fine but as the sourceobject changes in FRAME_3 i don't want to hard code the form names

(PS can anyone explain the "Form_" part of this is it some sort of internal Access reference?)

I also tried ;

Dim StrFrmName as String

StrFrmName = Form_FRM_STAFF_DETAILS.FRAME_3.SourceObject

' NB StrFrmName = "FRM_LEAVE"

CountRecordsDisplay forms(StrFrmName)

which doesn't work. I get the error "can't find the form FRM_LEAVE"



and

CountRecordsDisplay forms("FORM_" & StrFrmName)

which says the same thing as well.


Any Ideas?

Cheers Chris

:confused:



PHP:
Public Function CountRecordsDisplay(Frm As Form)


blah blah....

End Function
 
Honestly, your post confused me a bit, and I've never used the "Form_" syntax to refer to a form, but I can try to help you with subform references.

Let's say your main form is called frmMainForm and that your subform is called fSubForm. In full glory, the syntax to refer to a control called txtBox1 on the subform is:
Forms("frmMainForm").Controls("fSubForm").Form.Controls("txtBox1")
Just replace any piece within quotation marks with a variable, if you wish to refer to a different form, subform, or control.

If you are using a function to count the records displayed on a form, you should be able to pass the subform to it using that syntax.
 
As far as I know, you can pass a form to a sub/function as a parameter.

Are you 100% sure you are passing the right form name?

RichM
 
Hi

Sorry for lack of clarity; probably trying to be to clever for my own good.


I have a main form called FRM_FRAMES that contains 2 unbound subforms. the first is called FRAME_1 and can contain a variety of menus(buttons) depending on selections made.

The second is called FRAME_2. This displays data/frms.

In this case i click a button on the menu in FRAME_1 and this is replaced by a new menu and a new form is displayed in FRAME_2. In this case the form is called FRM_STAFF_DETAILS.

This form also has an unbound subform called FRAME_3. This is simply because i have a number of tbls/frms related to the staff members so i can display them as required in the unbound subform FRAME_3

So i have;

Mainform "FRM_FRAMES"
Which has a subform(FRAME_2)
In which is displayed "FRM_STAFF_DETAILS"
And this has a subform (FRAME_3)
Which in for this e.g displays "FRM_LEAVE"

As the form in FRAME_3 changes i would like to be able to pass the forms to the function without hardcoding the form names

something like;



Dim StrFrmName as String

StrFrmName = Forms!FRM_FRAMES!FRAME_2!FRAME_3

' NB StrFrmName = "FRM_LEAVE"

CountRecordsDisplay forms(StrFrmName)


Should you pass the form name i.e FRM_LEAVE or the Subform name i.e FRAME_3 and in either case what is the correct syntax

DCX693 in your example

Forms("frmMainForm").Controls("fSubForm").Form.Controls("txtBox1")


I would need something like


Dim StrFrmName as String

StrFrmName = Forms!FRM_FRAMES!FRAME_2!FRAME_3

CountRecordsDisplay Forms("FRM_FRAMES").Form("FRAME_2").Controls(strFrmName)


The piccy shows this better than i can explain.
R-BASE TM is FRM_FRAMES

Menu is FRM_MENU1 in the subform FRAME_1
Staff details is FRM_STAFF_DETAILS in subform FRAME_2 of FRM_FRAMES

Leave dates is FRM_LEAVE in subform FRAME_3 of FRM_STAFF_DETAILS.




Apologies if this is still not clear.

Thanks
Chris
 

Attachments

Last edited:
Chris
<<
I have a main form called FRM_FRAMES that contains 2 unbound subforms. the first is called FRAME_1 and can contain a variety of menus(buttons) depending on selections made.
>>

First, let's be clear on this:
<<
The first is called Frame_1
<<
Is that the name of the *control* on FRM_FRAMES ???
You have to pass the form name, not the *control* name.

Call SomeSub
(Forms![FRM_FRAMES]![FRAME_1].SourceObject)
is the correct syntax.



Second, SourceObject returns a string. So

Sub SomeSub(ByVal FormName As String)
Dim frmTemp As Form
frmTemp = Forms(strName)

HTH,
RichM
 
Hi Rich

Thanks for your help, I don't know why this isn't working but i still get the error message "unable to find form ....". The form name is being "sent" to the function but the (SET?) frmTemp = Forms(strName) generates the error.

Not to worry. I was overly complicating things anyway.

Cheers

Chris
 
Chris,

One more thing.

The subform has to be "active".

See some of the various sample MDBs; Northwind, Solutions, etc.
One of them has an example of setting form properties via a sub/function.

RichM
 
You would have to pass the form

call SomeSub Forms![FRM_FRAMES]![FRAME_1].Form

sub SomeSub (frm as Form)

Using Forms![FRM_FRAMES]![FRAME_1].SourceObject only passes the name of the subform and leaves out the main form information.
 

Users who are viewing this thread

Back
Top Bottom