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

Can you update the record source through VB

Status
Not open for further replies.

Muddman

MIS
May 22, 2001
13
US
I am running a query and then displaying the results on a form. This works fine. I set the Record source properties of the form to my query and it displays nicely. Now, I would like to have about 7 more queries that would display on a form. The only way that I can think of getting around this is to create about 7 more forms and attach the correct query to each one individually. This sounds like a lot of extra work.

Is there any way through VB that I could set the record source property of ,say a Master form, just before I ran the query on it so that it displays on the Master Form. That way, I would only need one form instead of 7 copies of the first.

Any help would be great.

Thanks

 
It sounds like you're setting the RecordSource of a DataControl, not a form, is that right? And yes, you can change the query source of the DataControl. For an Adodc1, set the CommandType to 4-adCmdStoredProcedure. Then execute the query like normal, passing it the name(or path) of your query. You should be able to change the CommandType at run time, as long as Adodc1.Recordset is closed:
Adodc1.Recordset.Close
Adodc1.CommandType = adCmdStoredProc
Adodc1.Recordset.Open MyQuery, "Provider=Microsoft.Jet.OLEDB...."'fill in appropriate provider here
 
all you have to do is create an ADO rs containing the result set for the Query of interest and set it to the recordset property of the data control. Then you have to refresh the datacontrol. Assuming you have a grid connected to the data control, it will display the new results.


Set dcQueryResult.Recordset = rs
dcQueryResult.Refresh


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top