473,379 Members | 1,235 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Referencing controls on subform query

Hi,

a question about something that seems very simple at first glance:

is it possible to reference other controls of a subform in a query
window without referencing through the parent form? I want to do this
as I want to use same subform on two different parent forms. Main
problem is that the subform is not part of the forms collection.

The only workaround I found was setting the query in code in the
subform_Load event.

example

subform frmSubCal has 2 comboboxes, one for year and one for week
Rowsource of cboYear is based on Calendar.Year
Rowsource of cboWeek is based on Calendar.Week , where Year=cboYear.

when I try to create this condition in query window I have to reference
through the parent form:

.... WHERE Year=[Forms]![frmParent]![frmSubCal]![cboYear]

this will, of course, fail when I drop another instance of the subform
on another parent frmParent2.

is there a way to leave out explicit name *frmParent* or have something
like Me.Parent in there? I also tried creating a public function
getYear on the sub form, referencing like this:
Where YEAR=Form_frmSubCal.getYear()
but the subform is simply not member of the forms collection.

the only workaround I found was this in the subforms Form_Load event:

Me.cboWeek.RowSource = "SELECT ... WHERE (((vCalender.Year)=" & _
"[Forms]![" & Me.Parent.Name & "]![frmSubCal].[Form]![cboYear]))"

which appears a bit kludgy; seems to work with multiple instances of
the subform though.

In any case I want to avoid going through global variables or external
routines, the code on the subform should be self contained so that i
could drop the subform onto other forms without additional coding.

tia,
Axel

Apr 13 '06 #1
2 4020
Axel,
FWIW, Keri Hardwick did a really nice summary of referring to various
properties etc of forms and controls with examples, which is here on
AccessWeb. (good place to bookmark... it's the FIRST place I look when
I have a question.)

http://www.mvps.org/access/forms/frm0031.htm

Apr 13 '06 #2
Thanks Piet

for the interesting link. I had a look at this lots of options there
the one I tried

Me!Controlname

works in code alright but *not* in the query designer.

there I have to specify

Forms!Mainform!Subform!ControlName

which kind of defeats the purpose, as the subform could also be on
Mainform2, Mainform3 etc.

I also tried Forms("Subform name")!ControlName
and Forms("Subform name").Form!ControlName
but they all give errors. I think if there was a way to get at the "Me"
keyword in query designer it would be very useful (as the query would
refer to the instance directly, not through the (unknown) parent form)

But my workaround (see original post) works, so not to worry.

regards,
Axel
pi********@hotmail.com wrote:
Axel,
FWIW, Keri Hardwick did a really nice summary of referring to various
properties etc of forms and controls with examples, which is here on
AccessWeb. (good place to bookmark... it's the FIRST place I look when
I have a question.)

http://www.mvps.org/access/forms/frm0031.htm


Apr 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tony Williams | last post by:
I have a form on which there is a tabcontrol and on this onr of the tabpages is a tick box which opens Outlook with data from the main form and prompts the user to amend the message before being...
2
by: neptune | last post by:
I built a form to access a query with a 2 field primary key. It should use 2 controls to find the unique record and display the other field values on the form. In the criteria section of the...
3
by: shumaker | last post by:
This code from the subform works for getting the value of a field of the main form named "WorkSheet": MsgBox Form_WorkSheet.Recordset.Fields("Clerk").Value Each record in the mainform datasheet...
4
by: mplogue | last post by:
I have a form (frmMain) with a subform (frmSub), each with enumerated fields of the same name (txt1, txt2, etc). I'm trying to make a function that will take the values for each field in frmMain,...
3
by: google | last post by:
I'm developing an application for use within my company in Access 2003. I'm new to '03, the application I did for my former employer was in '97. The two applications have similar functionality...
6
by: Mat | last post by:
Dear all, What I want to do is be able to use a string to refer to a control on a subform. IE: Forms!("Form1!form2!controlA").name or
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
7
by: jundavid | last post by:
have a form and a subform. In the subform, I have a combo box which I would like to only show the records based on the control on the main form. Let say I have a record of employees which I would...
3
by: ManningFan | last post by:
Here's a fun one, mein froinds! I have a form. The form (call it MainForm) has a subform control (call it SubForm). The actual subform that SubForm displays can change based on choices made on...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.