Change recordsource for a subform

R

Rod Behr

I need to change RecordSource property of a subform using a macro.

To do so for a form, use the SetValue command:

Forms!FormName.RecordSource = "MyQuery"

However, this doesn't work for subforms:

Forms!FormName!SubFormName.RecordSource = "MyQuery"

Returns the error: "The object doesn't contain the Automation object
'RecordSource.'"

I have tried doing this using simple code - i.e. converting the rest of the
macro, which works, to a module. I then add the line above and get the same
error. I have tried:

Me!FormName!SubformName.Form.RecordSource = "MyQuery"

And get "Invalid use of 'Me' Keyword" error.

I really don't want to get fancy or write miles of code, I just want to
re-use an existing form by changing the RecordSource of a subform on it. The
idea is to click a button on the primary form to change the RecordSource
underlying the subform.
 
R

Rod Behr

Arvin, you are the man (although I thought I tried that syntax - must have
misspelt something).

I have another question regarding the exact same scenario, but setting the
LinkChildField and LinkMasterField properties, but I'll play nicely and start
a new thread.

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top