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

Change a subforms record source with a combo box

29
Access 2003
Windows XP

I have a form that is for tracking attendance at programs.
the main form is the program information, and the sub form is the attendance information.

I have 5 homes and need to switch between each home at any given time. Currently i use a tab form with 5 subforms attached filtering the attendance data for each home.

What i wish to do is select a home from a combo/list box and have 1 subform show me the data for that home. I really hate having 5 subforms that essentially do the exact same thing

If any one can help that would be great
Dec 28 '07 #1
9 16766
ADezii
8,834 Expert 8TB
Access 2003
Windows XP

I have a form that is for tracking attendance at programs.
the main form is the program information, and the sub form is the attendance information.

I have 5 homes and need to switch between each home at any given time. Currently i use a tab form with 5 subforms attached filtering the attendance data for each home.

What i wish to do is select a home from a combo/list box and have 1 subform show me the data for that home. I really hate having 5 subforms that essentially do the exact same thing

If any one can help that would be great
The general syntax for changing the Record Source of a Sub-Form from a Main Form would be:
Expand|Select|Wrap|Line Numbers
  1. Me![<SubFormControl>].Form.RecordSource = "Select * From <RecordSource_of_SubForm> Where & _
  2.                            [<Unique_Field_in_Child_Form>] = " & Me![<Bound_Combo_Column>] & ";"
P.S. The Link Child and Master Fields cannot contain values.
Dec 28 '07 #2
Hi Fry

I would use above soln if all forms are exactly identical in terms of fields that are being displayed and updated and layout is the same. Just thought I'd throw in another alternative, and one that works great, especially if you do have uniquely different subforms depending on house...

1. Make subform names conform to a naming convention
You can either store the full name of the subform in the Combobox for the home, or one thing I've done is controled the naming of my subforms to match a code/key field identifying the home. For example

attendance data for Home 1 (A Unique identifier = H1) --> fsubAttendH1
attendance data for Home 2 (A Unique identifier = H2) --> fsubAttendH2
... etc

2, Create Main form (ie frmMain) with a subform control that has been assigned a generic Name property (ie fsubChild)

3. Add your Home selection combo to the Main (frmMain) form

4. Use the Home selection combobox's After Update event to set the subforms's SourceObject property. For example, let's say the unique code for the home (ie H1, H2, H3) is in Column(0). You could use something like

/untested code

Private Sub cboPickHouse_AfterUpdate()

Dim strSubFrmName As String

strSubFrmName = "fsubAttend" & Me!cboPickHouse.Column(0)

Me!fsubChild.SourceObject = strSubFrmName

'Following not manditory, but I like to set the focus in the subform
Me!fsubChild.SetFocus

End Sub

5. Remember that the subform is loaded before the main form, so you may want a default there.

Hope this helps,
RandomElle

Access 2003
Windows XP

I have a form that is for tracking attendance at programs.
the main form is the program information, and the sub form is the attendance information.

I have 5 homes and need to switch between each home at any given time. Currently i use a tab form with 5 subforms attached filtering the attendance data for each home.

What i wish to do is select a home from a combo/list box and have 1 subform show me the data for that home. I really hate having 5 subforms that essentially do the exact same thing

If any one can help that would be great
Dec 29 '07 #3
ADezii
8,834 Expert 8TB
Hi Fry

I would use above soln if all forms are exactly identical in terms of fields that are being displayed and updated and layout is the same. Just thought I'd throw in another alternative, and one that works great, especially if you do have uniquely different subforms depending on house...

1. Make subform names conform to a naming convention
You can either store the full name of the subform in the Combobox for the home, or one thing I've done is controled the naming of my subforms to match a code/key field identifying the home. For example

attendance data for Home 1 (A Unique identifier = H1) --> fsubAttendH1
attendance data for Home 2 (A Unique identifier = H2) --> fsubAttendH2
... etc

2, Create Main form (ie frmMain) with a subform control that has been assigned a generic Name property (ie fsubChild)

3. Add your Home selection combo to the Main (frmMain) form

4. Use the Home selection combobox's After Update event to set the subforms's SourceObject property. For example, let's say the unique code for the home (ie H1, H2, H3) is in Column(0). You could use something like

/untested code

Private Sub cboPickHouse_AfterUpdate()

Dim strSubFrmName As String

strSubFrmName = "fsubAttend" & Me!cboPickHouse.Column(0)

Me!fsubChild.SourceObject = strSubFrmName

'Following not manditory, but I like to set the focus in the subform
Me!fsubChild.SetFocus

End Sub

5. Remember that the subform is loaded before the main form, so you may want a default there.

Hope this helps,
RandomElle
Nice approach, RandomElle. Just for curiosity, I'm assuming that the Record Sources for each unique Sub-Form are predefined, is this correct?
Dec 29 '07 #4
frys
29
Thanks both of you. i have not had enough spare time to try your suggestions but i will post as soon as i have. t
Dec 31 '07 #5
ARH64
4
I have been searching for how to do something like this for a few days and stumbled upon this link.

Unfortunately, I'm confused. For one thing, how does one determine the Source Object of a main form's subform?

Also, do I make multiple subforms and the main form calls this subform based on my combo?

HELP!!!! :-)

Thanks.
Nov 10 '09 #6
ARH64
4
Here is what I am trying to do:

I have a main form: frmAssets

This main form as a combo to selet an asset type: cboAssetType

I have multiple subforms (five) which are called (I'll limit it to two):

tsfrmSoftwareDetails
tsrrmComputerDetails

If I choose Asset Type COMPUTER, I would like the appropriate tabbed subform to display. It I choose Asset Type SOFTWARE, I would like the software subform to display.

Can you help with this please?

Thanks!
Nov 10 '09 #7
ChipR
1,287 Expert 1GB
You might try using the AfterUpdate event of your combo box to make the appropriate subform .Visible = True, and hide the rest.
Nov 10 '09 #8
ARH64
4
I've tried that, ChipR, but it doesn't work as well as I'd like.
Nov 10 '09 #9
ARH64
4
I've got it working, RandomElle! Thanks so much! You're a genius!!!!!!

To your directions, I would add that the code must be added to the underlying table the cbo calls. For example, I added CD to the COMPUTER field of the Asset Type table.

Next, all subforms need to be renamed to the generic subform name noted with the code added. I named my subform a generic sfrmDetails and renamed all my subforms to accomodate this, for example sfrmDetailsCD.

The subform added to the main form must be unbound, named with the generic name, and the Source Object left blank.

Works PERFECTLY!!! YAY!!!!
Nov 10 '09 #10

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

Similar topics

0
by: CSDunn | last post by:
Hello, I have an Access 2000 ADP main form called frmAD_OpeningForm that needs to support several possible sub forms. The subform that should appear would be based on the combined bound values...
0
by: Jenni | last post by:
I currently have a query that is joining two distinct pools of information and turning them into one records with a unique identifier This query is dependent on criteria passed from a form in a...
6
by: Steve | last post by:
I have a form, primary subform and secondary subform. A tab control takes up all the area of the primary subform. There are about 15 tabs on the tabcontrol. Each tab contains fields from the same...
2
by: Jack | last post by:
Hi all, I searched the archives and found everyone happy with Stephen's MouseWheel On/Off code except for those with subforms. Stephen's page indicates that he has added code to handle subforms...
0
by: Jack | last post by:
Gday everyone, I'm dearly hoping Stephen Lebans is going to update his masterpeice to stop the mouse wheel scrolling to work on subforms *he has indicated this to me but of course beggers can't...
3
by: Diana Gard | last post by:
Perhaps this is a design flaw, please let me know. I'm using Access 2000. I have a form with a tab control and 5 subforms within those tabs. The forms match with the tables: Client main,...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
0
by: uthooker | last post by:
I have an Access form with some combo boxes in the Form Header that are enabled/disabled using conditional formatting based on the setting in a checkbox also in the Header (Combo box = Enabled by...
3
by: Phil | last post by:
I've posted this a few times without any luck, hoping for some fresh ideas on this. I'm pretty certain this can be done. I've been using a micrsoft template to create a supplier database called...
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: 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
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,...
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,...

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.