Change the query that a subform is based on by clicking a button

T

Timboo

I Admit it, Ive done some messy programing while I've been learning, and it
time to clean it all up. One thing I did was to open a different subform for
each of the query result I display, hence for 7 queries I have 7 forms all of
which are the same other than the fact that their source data is based on a
different query. What I really want to do is have one form, with the data
source based on which ever query is selected by a button on the main form.
So how do I change the data source by pressing a button? Probably simple
when you know how.

Thank you,

Tim
 
J

Jeff Boyce

A form has a RecordSource property, and an OpenArgs property.

If you start in Form1 and have the user click (or pick from a combo/list
box) the query they want, you can, in code behind that event, open Form2,
passing in an OpenArg value that is the name of the query. When the Form2
opens, you can have it check its OpenArgs and use the value there as its
RecordSource.
 
T

Timboo

Jeff, thank you, where do I find the OpenArgs statement or value to change
it? Thanks Tim
 
D

Douglas J Steele

You can pass something as OpenArgs as the 7th argument in the OpenForm
method:

DoCmd.OpenForm formname[, view][, filtername][, wherecondition][,
datamode][, windowmode][, openargs]

For example,

DoCmd.OpenForm "MyForm", , , , , , "This is an argument"

or

DoCmd.OpenForm "MyForm", openargs:= "This is an argument"



You can check what was passed as OpenArgs in a form using Me.OpenArgs.
 
T

Timboo

Jeff, Doug, thank you both, Im now off to try it! Cheers Tim


Douglas J Steele said:
You can pass something as OpenArgs as the 7th argument in the OpenForm
method:

DoCmd.OpenForm formname[, view][, filtername][, wherecondition][,
datamode][, windowmode][, openargs]

For example,

DoCmd.OpenForm "MyForm", , , , , , "This is an argument"

or

DoCmd.OpenForm "MyForm", openargs:= "This is an argument"



You can check what was passed as OpenArgs in a form using Me.OpenArgs.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Timboo said:
Jeff, thank you, where do I find the OpenArgs statement or value to change
it? Thanks Tim
 
Top