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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hot to refer to a Subform in a Tab Control from another tab 1

Status
Not open for further replies.

storl2

Programmer
Jun 3, 2004
47
US
I am not used to using bound controls, but I am helping another group add search to their database, so I am not sure what to do with this.

I have a database with a tab control in the main form, and two of the tabs are "search" and "edit project." I have a bunch of unbound controls in the search tab with a command button that creates a query used to open a recordset in the edit project tab, which is full of bound controls.

The query works fine, and I can make the sub open fine by itself when I take it out of the main form tabs and make it its own form, but how do I refer to it if it is a subform in the tabs?

I can't get docmd.openform to work, probably because the form is technically already open in the other tab, so how do I take the results of the search tab query and switch over to the edit tab and populate it with the results? I tried docmd.applyfilter after I set focus to the subform, but that did not work. The edit tab subform is just a simple form with bound controls and the navigation buttons.

I tried searching, but could not find an answer to this particular problem. Any help would be greatly appreciated.
 
Whoops, change the "hot" to "how" in the title.
 
Forget about the tabs. The subform can be referred to in the usual way:

Me.[Subform Control Name].Form

There after:
.SubformPropertyName
.[Subform Control Name]
 
But how do I apply the filter to the subform? Like I said, it works when I make it its own form, but when referring to it as a subform, I can't get the syntax right with docmd.openform or applyfilter.
 
Me.[Subform Control Name].Form.Filter = "ID=1"
Me.[Subform Control Name].Form.FilterOn=True

And so on.

 
Ah, I see what you mean. OK, I was wrong in trying to use the filter. A simple filter will not work. The search creates a dynamic query based on which controls are filled in in the search tab, so the criteria can be different every time, so there can be between 1 and 30 criteria. I need to use something like the wherecondition argument in docmd.openform.

Thanks for the help so far. You have been spot on according to what I described.
 
How about:

Me.[Subform Control Name].Form.RecordSource = strSQL

Where strSQL is the query created.
 
Say you had something like this:
DoCmd.OpenForm "Edit project", , , strWhere

you may use something like this:
Me![control hosting Edit project].Form.Filter = strWhere
Me![control hosting Edit project].Form.FilterOn = True

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Wow, duh! Thanks, Remou, that worked perfectly. I have always used unbound controls in my forms to avoid data issues, so I didn't even think of something like that. Maybe one day I will just make them a new database with naming conventions and all that fun stuff...

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top