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

How to open form with subset of data?

122 100+
This should be an easy one, but I can't figure it out.

frmProvider (data source: tblProvider) displays information about child care providers. Since tblProvider is fairly large, I am using a tabbed control to display all the fields on frmProvider.

In addition to the tabs which contain the provider information, I have another tab that displays a sub-form (sfrmProviderChildren) of the children registered to this provider. This sub-form gets it's data from a query that pulls data from tblChild and tblRegistration (a bridge table to tie tblProvider to tblChildren together in a many-to-many relationship). Then, the subform is tied to it's parent from with provider_id (child field) and id (master field).

A second form in the database, called frmChild, displays information on the children from tblChild.

I have a control (cmdAddKids) on frmProvider that is supposed to open frmChild with a subset of records that contains only the children registered to the current provider.

Here are the structures for the tables involved:
tblProvider
tblprovider.id (PK)
tblprovider.lname
tblprovider.fname

tblChild
tblchild.id (PK)
tblchild.lname
tblchild.fname

tblRegistration
tblRegistration.provider_id (PK)
tblRegistration.child_id (PK)
Here is my code, but it opens frmChild with all kids instead of just the ones registered to to the current provider:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAddKids_Click()
  2. On Error GoTo Err_cmdAddKids_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "frmChild"
  8.     stLinkCriteria = "[tblAssignment].[provider_id]=" & Me![id]
  9.  
  10.     DoCmd.OpenForm stDocName, , , , acFormEdit
  11.  
  12. Exit_cmdAddKids_Click:
  13.     Exit Sub
  14.  
  15. Err_cmdAddKids_Click:
  16.     MsgBox Err.Description
  17.     Resume Exit_cmdAddKids_Click
  18.  
  19. End Sub
Help??
Jun 23 '08 #1
9 3768
puppydogbuddy
1,923 Expert 1GB
Change Line 10 of your code:
>>>>>>>> DoCmd.OpenForm stDocName, , , , acFormEdit

To This:
>>>>>>>> DoCmd.OpenForm stDocName, , ,stLinkCriteria , acFormEdit
Jun 23 '08 #2
Annalyzer
122 100+
I had the criteria in there originally, but it didn't recognize the field provider_id.

As a side note, I just realized that I posted the actual code from my database, but the table structure and explanation refer to tblAssignment as tblRegistration (I thought that would make more sense). In the actual database, the table names do actually match:
tblProvider
tblprovider.id (PK)
tblprovider.lname
tblprovider.fname

tblChild
tblchild.id (PK)
tblchild.lname
tblchild.fname

tblAssignment
tblAssignment.provider_id (PK)
tblAssignment.child_id (PK)
Even with the right table names and the criteria included in the string, it doesn't work. It doesn't recognize tblAssignment.provider_id and so pulls no kids into the form at all. When I remove the criteria, of course, it pulls all kids into the form.
Jun 23 '08 #3
PianoMan64
374 Expert 256MB
I had the criteria in there originally, but it didn't recognize the field provider_id.

As a side note, I just realized that I posted the actual code from my database, but the table structure and explanation refer to tblAssignment as tblRegistration (I thought that would make more sense). In the actual database, the table names do actually match:

tblProvider

tblprovider.id (PK)
tblprovider.lname
tblprovider.fname

tblChild
tblchild.id (PK)
tblchild.lname
tblchild.fname

tblAssignment
tblAssignment.provider_id (PK)
tblAssignment.child_id (PK)
Even with the right table names and the criteria included in the string, it doesn't work. It doesn't recognize tblAssignment.provider_id and so pulls no kids into the form at all. When I remove the criteria, of course, it pulls all kids into the form.
I have a question, is there ever a case where a child is going to have more than one provider and any one time or could a child have more than one provider?
Jun 23 '08 #4
puppydogbuddy
1,923 Expert 1GB
If your button is on the main form, try this:

Change this:
stLinkCriteria = "[tblAssignment].[provider_id]=" & Me![id]

To this:
stLinkCriteria = "[tblAssignment].[provider_id]=" & Me!YourSubformControl.Form![id]

Replace YourSubformControl above with the actual name of your subform control.
Jun 23 '08 #5
Annalyzer
122 100+
Yes, Piano Man, most of the kids have more than one provider. Some have 2 and a few have 3 (in case their main provider is ill, they need a backup place to go). In my original database, frmChild had 3 fields for primary, secondary, and tertiary, but then along came the child with - you guessed it - 4 providers! I can't imagine needing 3 backup providers, but apparently some parents believe in redundancy ad infinitum.

PuppyDogBuddy, I tried your idea, but I get the message "Access can't find the field 'provider_id' referred to in your expression."

Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[tblAssignment].[provider_id]=" & Me![provider_id].Form![id]
  2.  
  3. DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit
provider_id is the control on the subfrom (sfrmKids4ProviderForm) since it pulls it's data using a query that INNER JOINs tblProvider with tblAssignment. Even when I qualify it:

Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[tblAssignment].[provider_id]=" & Me![sfrmKids4ProviderForm!provider_id].Form![id]
  2.  
  3. DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormEdit
Access still can't find that ...field? control?

This is making me dizzy. lol
Jun 23 '08 #6
puppydogbuddy
1,923 Expert 1GB
Ok, if you are referring to a nested 2nd level subform from the main form, the syntax is like this:

Me!Subform1.Form!Subform2.Form!ControlName

useing this link as a guide (for future reference):

http://www.mvps.org/access/forms/frm0031.htm
Jun 23 '08 #7
Annalyzer
122 100+
No, there is only 1 subform (sfrmKids4ProviderForm) with a control named provider_id. This subform resides on frmProvider which has a control named id. So, if I'm understanding you correctly, the syntax should be:

Expand|Select|Wrap|Line Numbers
  1. stLinkCriteria = "[tblAssignment].[provider_id]=" & Me![provider_id].Form![id]
However, this syntax throws the error message: "Access can't find the field provider_id referred to in your expression."

Am I misunderstanding?
Jun 23 '08 #8
puppydogbuddy
1,923 Expert 1GB
Ok, you have been confusing me with different names for your subforms (see below). Also, you indicate that you want to open the subform, but in your code you are opening frmChild.


Forms………………………Record Sourrce
frmProvider…………………..tblProvider.[id]
sbfrmProvderChildren…….qryXXXX..[provider_id]
sfrmKids4ProviderForm…. qryXXXX..[provider_id]
frmChild…………………..tblchild.[id]

Is the button is to open frmChild or is it supposed to open sfrmKids4ProviderForm from the main form?

If the intent is to open the subform, and not frmchild , try the following code.


1. stDocName = "sfrmKids4ProviderForm"
2. stLinkCriteria = "[tblAssignment].[provider_id]=" & Me![id]
Jun 23 '08 #9
Annalyzer
122 100+
You know, I think maybe that's the biggest part of my problem. I'm confusing myself with the names and data sources of all these objects. I originally threw together this database in about a week and a half to prevent losing some funding and now I'm trying to clean it up. I've renamed so many things and rewritten so much code that I can't remember what's what.

Throw into that the fact that I'm now under the gun to finish up some programming projects in another database on a LAMP system and create some budgeting spreadsheets in Excel that do everything managers need them to do without allowing them to delete any formulas or budget any expenses to grants that aren't supposed to be paid from those grants and sometimes I wonder which way is up. Half the time I can't remember if I'm supposed to be thinking in Access, MySQL, PHP, Linux, or Excel. I feel like I'm just putting band-aids on what's wrong instead of fixing things the right way.

I think it's time to go back to the ERD on this one and start from scratch. If, after that, I'm still having problems, I'll be back. I'm sorry I've wasted your time and I truly appreciate all your help and tenacity. YOU ROCK, puppydogbuddy!
Jun 24 '08 #10

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

Similar topics

29
by: Chris Dutrow | last post by:
I searched around on the net for a bit, couldn't find anything though. I would like to find some code for a function where I input A Range Of Integers For example: Function( 1, 100 ); And the...
2
by: Dave | last post by:
Hello all, I have a class that contains a large number of discrete pieces of state information. Any combination of these member variables might be valid for a given object. Any given member...
55
by: Steve Jorgensen | last post by:
In a recent thread, RKC (correctly, I believe), took issue with my use of multiple parameters in a Property Let procedure to pass dimensional arguments on the basis that, although it works, it's...
1
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside...
4
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the...
6
by: ultraton | last post by:
While trying to print a report from Access the user receives the following error: Cannot open any more databases. Okay Help Does anyone have any ideas about this behavior? Thank you very...
8
by: PAPutzback | last post by:
How do I keep the form up.
4
by: magmike | last post by:
I've created a report for the purpose of printing a one page summary of a record. Of course, when I created the report, it gives me a page on every record. Can I create a button to open that report...
5
by: Ronald S. Cook | last post by:
From my business tier (class) I get back an IQueryable<Penof data. Here is my client code that works fine: PenClass penClass = new PenClass(); IQueryable<Penpens = penClass.SelectPens(); ...
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: 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
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...
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.