REusing same form with different queries?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there

I am builidng a db which will be used to look at data in different regions across canada. The data to be looked at is the same for all regions across the country, but i want to filter what data is seen

For example. On the welcome page, I have four buttons for the user to choose what region they are interested. Once that is selected, i want to use the same forms, but only show data for that region. If the user chooses a different region, then teh same forms could be used.

Can i do this without having to make separate forms for each region and assigning a defined query for them

thank you in advance

Carlee
 
Absolutely. You can include a parameter in the query that your reuseable
form is based on, like

WHERE Region = Forms![WelcomeForm].Form.txtRegion

assuming the Welcome form is open and you stored Region in txtRegion in
the Welcome form. If it is not, you should store the chosen region in
your reuseable form.
I personally would simply add the choice of Region to the reuseable form
so that the user can query different regions without going back and
forth between different forms.

Pavel
 
Thanks Pavel,

A further question,

What about forms that are showing data? For example, if a user clicks on the region they want and that opens an Agreement Entry form where only Agreements with that region are shown? I guess i am asking how do i switch the queries around given the region chosen?
 
Another option is to use the OpenArg option when opening the form.

DoCmd.OpenForm "NameOfForm", acNormal,,,,,"RegionInfo"

Change RegionInfo with some sort of identifier. Then in the Open event of
the form check for this information and set the RecordSource of the Form
based on this. Assuming you use 1-4 to identify the different regions.

Select Case Me.OpenArgs
Case 1
Me.RecordSource = "NameOfQuery1"
Case 2
Me.RecordSource = "NameOfQuery2"
Case 3
Me.RecordSource = "NameOfQuery3"
Case 4
Me.RecordSource = "NameOfQuery4"
End Select

Kelvin

Carlee said:
Thanks Pavel,

A further question,

What about forms that are showing data? For example, if a user clicks on
the region they want and that opens an Agreement Entry form where only
Agreements with that region are shown? I guess i am asking how do i switch
the queries around given the region chosen?
 
-----Original Message-----
Thanks Pavel,

A further question,

What about forms that are showing data? For example, if
a user clicks on the region they want and that opens an
Agreement Entry form where only Agreements with that
region are shown? I guess i am asking how do i switch the
queries around given the region chosen?
Hi Carlee,

you may want to re-read Pavel's post.

An alternative is to use the following as an example...

docmd.openform FormName:="frmAgreement",
WhereCondition:="[RegionID]=" & lngRegionID

this assumes have id numbers else for text use

docmd.openform FormName:="frmAgreement",
WhereCondition:="[Region]=" & chr(34) & txtRegion & chr(34)


Luck
Jonathan
 
Back
Top