473,387 Members | 1,502 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,387 software developers and data experts.

Subform requery not working from Main form

8
In Access 2007, my subform has 3 controls that filter data from queries based on user selections from the preceding controls using the requery macro. It works fine when I have only the subform open.

However, when I try to run it from the main form, the parameters do not pass to the next control. Instead, I get a dialog box to input the value. How do I get the subform to work from the main form? Thx.
Aug 18 '09 #1
15 12282
ADezii
8,834 Expert 8TB
@pl626
my subform has 3 controls that filter data from queries based on user selections from the preceding controls using the requery macro
Are you referring to a Combo Box on a Sub-Form? If so (Full Syntax):
Expand|Select|Wrap|Line Numbers
  1. Forms!<Main Form>!<Sub-Form Name>.Form!<Combo Box name>.Requery
Aug 18 '09 #2
ajalwaysus
266 Expert 100+
You need to give a more technically detailed explanation on what it is you are doing. But if I were to guess, sounds like you may have a master-child linking issue, from the main form to sub form.

-AJ
Aug 18 '09 #3
pl626
8
@ADezii
Yes, I have 3 Combo Boxes in the Sub-form. As I understand it, that code should be on the main form correct? For which event should this code be assigned, 'On Got Focus'? Thx.
Aug 18 '09 #4
pl626
8
@ajalwaysus
AJ-thx for the quick response. My main form captures data for the header record of the parent table and the subform feeds a child table. The linkages are fine. There is no data that is being passed from the main form to the subform for these 3 controls. These 3 controls apply only to the subform data. The first control is a Combo-Box with values the user selects. This value is used to filter results for selection in the second combo box, which acts as a filter for the third. In the subform, i'm using the requery macro for this and it works fine when only the subform is open.

I've tried using 'Forms![main form![subform.Form![CNX Secondary].Requery' with various events and can't figure out how to get it to work.
Aug 18 '09 #5
ajalwaysus
266 Expert 100+
First off, maybe you mistyped but your code should look like this:
Expand|Select|Wrap|Line Numbers
  1. Forms![main form]![subform].Form![CNX Secondary].Requery
  2.  
and just to cover the bases, just to make sure it was done, you replaced the [main form] and [subform] values with the actual names of your form, correct?

If this is still an issue, another option you could do, is to set the after update of each combo box to re-query the next combo box in the subforms VBA code.

Eaxmple:
Expand|Select|Wrap|Line Numbers
  1. Sub ComboBox1_AfterUpdate()
  2.     ComboBox2.requery
  3. End sub
  4.  
  5. Sub ComboBox2_AfterUpdate()
  6.     ComboBox3.requery
  7. End sub
  8.  
-AJ
Aug 18 '09 #6
pl626
8
AJ,

i did mistype in my response, the syntax i used is:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.       Forms![MainFormName]![subFormName].Form![controlname].Requery
  3. End Sub
Is there are different event on the main form I should be using?
Aug 18 '09 #7
ajalwaysus
266 Expert 100+
If all 3 of your combo boxes exist on the subform then you should code the After update code I provided above, directly in subFormName 's VBA code.

When coding on the same form as where the controls exists, you then don't have to worry where you place that subform, because the code is native to that form.

-AJ
Aug 18 '09 #8
NeoPa
32,556 Expert Mod 16PB
@pl626
From this it seems you have omitted to change the text (MainFormName) to the actual name of your form. That is, unless it is actually called MainFormName, but that would be a very bad idea, so I'm sure you haven't. The same goes for the names of other objects in the reference of course.

Perhaps if you shared the names of all the object references involved on your form we could determine the full code reference for you if you need us to.
Aug 18 '09 #9
pl626
8
I updated the code in the subform and it works fine in the subform, but now when I run the subform from the main form, I get a "Run-time error '2450' " stating it can't find my subform. Do I need to add code in the main form to reference the subform?
Aug 18 '09 #10
NeoPa
32,556 Expert Mod 16PB
I thought that was already discussed, but maybe I'm losing my comprehension here of what's been covered and what's not.

May I suggest you have a play with Example Filtering on a Form. This may help you to do what you want to do without some of the referencing issues.

If you need, we can look again at exactly what you need in your referencing code, but hopefully this link will help you do the whole thing more simply. Let us know how you get on.
Aug 18 '09 #11
pl626
8
@NeoPa
Thx NeoPa, unfortunately, I need to use the subform as it populates the child table. The main form has bound objects that populate the header table. I'm certain my problem is referencing the subform from the main form, but I'm not certain from which event to code the subform requery or do I need to declare some variables?
Aug 19 '09 #12
ajalwaysus
266 Expert 100+
Could you post a screen shot of your main form with the subform, and perhaps the code on both as it stands now, because I am having a hard time understanding why you can't place after update code on your subform.

-AJ
Aug 19 '09 #13
pl626
8
@ajalwaysus
I just sent you a PM. I can't shrink down the screenshots without rendering them useless, but I can e-mail you. BTW, the code you suggested no longer results in the '2450' error, but it behaves just like the macro does, i.e., I am prompted for the parm value for the first control when I execute the second control. I also added a macro to open the subform, which kind of fixes the problem, but not quite. The parm prompt goes away, but the bound query doesn't really execute.

I'm certain the issue is a referencing issue, I just can't figure out what it is.
Aug 19 '09 #14
pl626
8
AJ,

No worries, the problem was with the syntax in the bound queries. Once I appended the SQL with the fully qualified name, [Forms]![mainform]![subform], everything works perfectly. Thx for your support on this.
Aug 19 '09 #15
ajalwaysus
266 Expert 100+
No problem, ADezii deserves most credit for providing the platform to get this started, good luck in the future.

-AJ
Aug 19 '09 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bill Strass | last post by:
Problem: Access main form/subform as front end to SQL Server backend. Add/edit via subforms work fine. Not so with main form. Set up a master-detail form-subform using two views linked from SQL...
2
by: TDIOwa | last post by:
I have a form (frmAppointment) with a subform on it (frmAppointmentsub1). I have placed a command button on the main form which calls the function below from the module. The purpose of this...
2
by: prakashwadhwani | last post by:
I have a (Main) form named : Stocks_Main and a Subform in that named: Stocks_Data The Subform is a continuous form There is a field in the subform called QTY_IN Now ... on the main form i.e....
3
by: wideasleep | last post by:
Hi everyone, I have a subform that is a continuous form. It will have mutiple records that connect to a single record in the main form. I have set this up but running tests show only one record...
0
by: Richnep | last post by:
Hi all,. I have a small issue I would like to resolve with VBA. I have a form which it's fields are bound to a table. Within that form is a subform which is a subtable. Tables relationship...
1
by: ssr61 | last post by:
hi can u help me how to open a sub form with in a main form without opening a new window..... my main form (frm_searchby_Name)consists of text field to enter the address and button when...
2
reginaldmerritt
by: reginaldmerritt | last post by:
Not sure if this is even possible, but i want to select a field in a sub form from a main form. I want to populate a field in the main form with a sub forms field value. eg. me.name =...
1
by: Bob Alston | last post by:
I have a system where many subforms are used. Often the size of the subform had to be larger than could be displayed without scrolling. I set the height of the subform to the typical height...
2
by: ndeeley | last post by:
Hello, I've not had a lot of luck getting this to work, despite looking around lots of websites, so here goes... I have a main form frmProjectScheduler. It's a tabbed form and the front page is...
6
Fspinelli
by: Fspinelli | last post by:
I have a query by form set up. I coded and can get the fields on the form to clear by the click of a button, but how do I make the subform clear, too? The main form has a "Clear" button and in...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.