refer a control form a sub form

A

Ac

I have two forms named Form1 and Form2. Form1 contains a sub-form subform1.
How can I refer a control on the Form2 from subform1? Thanks
 
M

Minton M

I have two forms named Form1 and Form2. Form1 contains a sub-form subform1.
How can I refer a control on the Form2 from subform1? Thanks

Call Me.Parent.Form.ControlName to access the control.

-- James
 
K

Klatuu

First, you need to be sure Form2 is open:

If CurrentProject.Allforms("Form2").Isloaded Then
Forms!Form2!MyControl = "Foobah:
End If
 
A

Ac

Thank you for your reply.

My form2 is a start form, there is a combo box named year on it. The form2
contains a sub form; I would like to change the sub form’s Record Source to
open each query displaying records on sub form corresponding to the year
selected from the combo box on the Start form. Here is the code for sub form
which I have now, it does not work. The message I got is the unknown form
Start. Please help me for the code. Thanks!



Private Sub Form_Load()

Dim year As String

year = Forms!Start!cboYear
year = Right(year, 2)
year = CStr(year)


Me.RecordSource = "q" & year & "Sum_US" ‘It is the query’s name
which I like to connect to

End Sub
 
K

Klatuu

This is very different from your original question. And, you have a design
flaw that needs addressing. It is not necessary to have a different query
for each possible year.

Use one query that filters on the value in the combo box.
Then use the After Update event of the combo to requery the subform.
Me.MySubformControl.form.requery
 
A

Ac

Thanks Klatuu,

Each query is generated by different calculations, there are not on one
query. The way I would like to connected the query because of that reason. Is
that possible to connect the query like that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top