Full Version: Give (PASS) -- sub form -- SQL Command
UtterAccess Forums > Microsoft® Access > Access Forms
Give sub form SQL Command
This is very important for me :
If I have 2 form main form and subform
I want by command button on the main form give this subform sqlcode to execute
Is this possible (in any way)
I hope this
Doug Steele
What do you mean by "give this subform sqlcode to execute"?
QL really isn't specific to a form: SQL affects the underlying tables and therefore can be run from anywhere.
Thank you for your help and reply
mean can i change the record source of the sub form at run time
the sub form (((record source = SELECT * FROM Table2; )))
Omean change SELECT * FROM Table2; to another sql command :
ok i will tell you the story
i have data base contain 10000 record
i'm using this way to filter my data base:
forms!form1!text1 or forms!form1!text1 is null
for 5 or 6 controls in query
after some time this message appear
Query very complex
so if i can change the subform record source to another sql i can ignore this message and will not appear again
I hope you understand me
i'm waiting you comments and waiting the help
compute.gif compute.gif
notes :
i think that i can use text box in main form and and use defult value to sql command and tell the subform record source to this text box
like this
sub from record source = forms!form1!text1
but not work with me
can you think in this operation
If both are bound, the form and subform are linked by Parent/Child properties. If you match the fields that establish this parent/child relationship, you don't have to keep reseting the subform. It will just reset by itself as you scroll through the main form.
i don't want use link child and link master for many reason
I want display all my records
not flexible
Doug Steele
And if the parent form isn't bound, you can change the RecordSource of the subform using:
orms![NameOfParentForm]![NameOfSubformControl].Form.RecordSource = "SQL Statement"
Forms![NameOfParentForm]![NameOfSubformControl].Form.RecordSource = "NameOfQuery"
Note that depending on how you added the subform to the parent form, the name of the subform control on the parent form may not be the same as the name of the form being used as a subform.
Have you tried using a filter on the subform?
When the user clicks the button, you can use
Me.[Name of Subform].Form.Filter = "[Field Name] = " & Me.[Control Name]
Me.[Name of Subform].Form.Filter = "[Field Name] = '" & Me.[Control Name] & "'"
Me.[Name of Subform].Form.Filter = "[Field Name] = #" & Me.[Control Name] & "#"
Me.[Name of Subform].Form.FilterOn = True

Choose only ONE of those filters depending if it's a number, string, or date respectively. To reset to all records, use
Me.[Name of Subform].Form.Filter = ""
Doug Steele, Microsoft Access MVP
Greg Serrano
Thanks for the help
thanks.gif thumbup.gif
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.