Help - How to use a Button to change a form data source (1 Viewer)

russ1985

Registered User.
Local time
Today, 23:46
Joined
Mar 12, 2009
Messages
18
I have a form which i want to be able to click a command button and it change the record source of the form from a specific table to a query (which will ask for a parameter to search the table and change the form to show the matching record).

can anyone help with some ideas for coding the button to do this.

Skill level - Beginner/Intermediate
software: Access 2007
system: Vista :( (miss XP, cant afford 7)
 

ghudson

Registered User.
Local time
Today, 16:46
Joined
Jun 8, 2002
Messages
6,195
In the OnClick event of a command button...

Code:
Me.RecordSource = "Your Query or SQL"
Me.Requery [COLOR="Green"]'Not sure if you have to requery but just in case.[/COLOR]
 

Kryst51

Singin' in the Hou. Rain
Local time
Today, 15:46
Joined
Jun 29, 2009
Messages
1,898
I have a form which i want to be able to click a command button and it change the record source of the form from a specific table to a query (which will ask for a parameter to search the table and change the form to show the matching record).

can anyone help with some ideas for coding the button to do this.

Skill level - Beginner/Intermediate
software: Access 2007
system: Vista :( (miss XP, cant afford 7)

Out of curiosity, why not just base the form off of the query anyway? or use a combo box that uses the query that will find the record you want? Then you wouldn't have to code a record source change.
 

russ1985

Registered User.
Local time
Today, 23:46
Joined
Mar 12, 2009
Messages
18
Hi Thanks for the code worked a treat.

to answer your question i want to save the user needing to open a different form for different queries and tables. much better to just have a button to change the record source to run from a different table/query.

thanks again.
 

Users who are viewing this thread

Top Bottom