Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Subform Recordset from Mainform's code

Status
Not open for further replies.

Cybernetic2002

Programmer
Nov 20, 2001
7
CA
In my project there is a subform that needs to have it's RecordSource updated dynamically through code.

When the user changes the record on the main form, I want the subform to be updated to match the mainform. In order to do this I have to change the subform's RecordSource(Could also use the Filter property) each time the Main form changes to a different record.

In my Main Form_OnCurrent it changes the ID# on the subform to match that of the Main form. But when I try to change the RecordSource of the mainform Access comes back with error# 438: Object doesn't support this property or method.

Here is the code I am using to assign the subform's recordsource. As far as I can tell there is no way to set the recordsource in a subform unless it is actually done in that subform's module.

Forms!qBookings.frmqCars.RecordSource = carRecordSource

If anyone could help me with this or has any other ideas that could make this work I would appreciate it greatly. I am getting desperate as this project is starting to become LARGELY overdue. HELP ME PLEASE!!!

Cyb.
 
Looking at your code, it looks as if you have specific booking-types. Depending on how many booking-types you have, will influence the most efficient solution.

I have used the following technique extensively, & with no trouble. However, if you have a very large number of booking types, it could get a littel cumbersome to manage. Instead of changing the recordsource, create an empty subform container on your mainform. Next create a subform for each type of booking. Then, based upon the booking-type assign the empty container a sourceobject, & link the master/child fields.
e.g
Create empty subform container called SubformLoader


With Me.SubformLoader
Select Case Me!BookingType
Case = 1
.SourceObject = "frmBookingType1"
.LinkMasterFields = "PrimaryKeyField"
.LinkChildFields = "PrimaryKeyField"
Case = 2
.SourceObject = "frmBookingType2"
.LinkMasterFields = "PrimaryKeyField"
.LinkChildFields = "PrimaryKeyField"
Case = n
.SourceObject = "frmBookingTypen"
.LinkMasterFields = "PrimaryKeyField"
.LinkChildFields = "PrimaryKeyField"
End Select
End With


I think this will do what you need to do, but an untested alternative I can think of is:

How about assigning the recordsource from the subform itself. I am not sure if this would work, but perhaps you could write a sub within the subforms code, which will assign the recordsource. You could then call this from the mainform & pass in a key which will identify which recordsource to use.
James Goodman
 
Thanks for the help, however another user already told me my problem. I just had the wrong syntax. The above looks like it will work so if I have anymore problems I'll try that. Thanks again.

Cyb.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top