473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Reusing a Form

I have a form I would like to use in front of several queries. For
example, I want to use frmA but only looking at the records retrieved
by qryX. Then I want to use frmA again, but only looking at the records
retrieved by qryY. Then be able to reuse frmA to view records from
qryZ. My reasoning is that if the form changes, I don't have to
manipulate multiple forms. There will be approximately 20 such queries.
Has anyone done something similar? If so, how?

Don Glenn

Nov 13 '05 #1
10 3986

<gl******@cox.net> wrote
I have a form I would like to use
in front of several queries. For
example, I want to use frmA but
only looking at the records retrieved
by qryX. Then I want to use frmA
again, but only looking at the records
retrieved by qryY. Then be able to
reuse frmA to view records from
qryZ. My reasoning is that if the form
changes, I don't have to manipulate
multiple forms. There will be approxi-
mately 20 such queries.


Three ways come immediately to mind... on the guess that the Form you
mention is bound to the Query, and that you are opening it from VBA with a
DoCmd.OpenForm statement.

It seems that the only difference between the Queries is which Records are
returned, not a different set of Fields (which could, perhaps, be handled
with a single Form, but wouldn't be as easy).

The DoCmd.OpenForm has two arguments in which you can supply criteria to
limit the Records from the Form's RecordSource: FilterName and
WhereCondition. In at least some versions of Access, you can pass the name
of a string containing a complete SQL statement in the Filter or Where
Condition arguments, if you'd rather. You could use one of those, or,
perhaps more efficiently, use the OpenArgs argument to pass the exact SQL
which you use to replace the Form's RecordSource in the Form's Open event.

Larry Linson
Microsoft Access MVP
Nov 13 '05 #2
By using the Recordsource property of the form. If you set that to
another recordset, voila.

Data will show only if the fields have the same names.

gl******@cox.net wrote:
I have a form I would like to use in front of several queries. For
example, I want to use frmA but only looking at the records retrieved
by qryX. Then I want to use frmA again, but only looking at the records
retrieved by qryY. Then be able to reuse frmA to view records from
qryZ. My reasoning is that if the form changes, I don't have to
manipulate multiple forms. There will be approximately 20 such queries.
Has anyone done something similar? If so, how?

Don Glenn


--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html

Nov 13 '05 #3
"Larry Linson" <bo*****@localhost.not> wrote in
news:nUFue.2579$HU.1674@trnddc03:
<gl******@cox.net> wrote
I have a form I would like to use
in front of several queries. For
example, I want to use frmA but
only looking at the records retrieved
by qryX. Then I want to use frmA
again, but only looking at the records
retrieved by qryY. Then be able to
reuse frmA to view records from
qryZ. My reasoning is that if the form
changes, I don't have to manipulate
multiple forms. There will be approxi-
mately 20 such queries.


Three ways come immediately to mind... on the guess that the Form
you mention is bound to the Query, and that you are opening it
from VBA with a DoCmd.OpenForm statement.

It seems that the only difference between the Queries is which
Records are returned, not a different set of Fields (which could,
perhaps, be handled with a single Form, but wouldn't be as easy).

The DoCmd.OpenForm has two arguments in which you can supply
criteria to limit the Records from the Form's RecordSource:
FilterName and WhereCondition. In at least some versions of
Access, you can pass the name of a string containing a complete
SQL statement in the Filter or Where Condition arguments, if you'd
rather. You could use one of those, or, perhaps more efficiently,
use the OpenArgs argument to pass the exact SQL which you use to
replace the Form's RecordSource in the Form's Open event.


Or, have the form by default open with an empty recordsource, then
choose which data set you want to load from, say, a dropdown list,
the AfterUpdate event of which would set the form's recordsource.

The way I create empty recordsets is to pick the smallest table in
the application, then do a TOP 1 query on it. I then return no
fields from that table, but instead:

SELECT Null as YourField1, Null As YourField2

and so forth.

The result is a non-editable single-record record source that loads
very fast, but has all the fields the controls on the form are bound
to (as opposed to having a blank recordsource, which will cause the
#NAME error to show in all the controls).

I don't see any merit to use OpenArgs for passing SQL or filters
when you already have a mechanism for passing a WHERE clause as a
dedicated argument to the OpenForm method.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #4
Or you can create several queues list in the form, when someone opens
the form, they choose their own queue to output different info for each
different queue. this will pull from a queue table having an SQL .

Nov 13 '05 #5
Larry: Thanks for the quick reply. You are correct, I want to use the
same exact fields, but apply 20 different filters on the data based on
what the person wants to work on. I just don't want to maintain 20
queries and 20 forms.

I will try your answer as I think it is the easiest and therefore the
most elegant.

Don Glenn

Nov 13 '05 #6
On 24 Jun 2005 07:48:46 -0700, "gl******@cox.net" <gl******@cox.net> wrote:
Larry: Thanks for the quick reply. You are correct, I want to use the
same exact fields, but apply 20 different filters on the data based on
what the person wants to work on. I just don't want to maintain 20
queries and 20 forms.

I will try your answer as I think it is the easiest and therefore the
most elegant.

Don Glenn


Just to add my 2 cents...

I've found that it's not good for the code that launches the form to be too
tightly coupled to -how- the form displays its records. Thus, rather than
pass the criteria using the FilterName or WhereCondition clauses, I prefer to
pass the criteria using OpenArgs, and let the form build the SQL or apply a
filter to itself during its Open event handler.

One example of where this technique pays off...

You open the same form from 10 different calling procedures, and now you find
you need to present the form data in a subform of the main form. You can't
simply apply the criteria to the main form because it's not the one bound to
the data, and there are now 10 places the code would have to be changed to
accomodate the new master/sub form design. Careful - don't miss one.
Nov 13 '05 #7
cl*****@attglobal.net wrote in
news:11**********************@g47g2000cwa.googlegr oups.com:
Or you can create several queues list in the form, when someone
opens the form, they choose their own queue to output different
info for each different queue. this will pull from a queue table
having an SQL .


"Queue?"

I have no idea what you're talking about with that term.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8
"gl******@cox.net" <gl******@cox.net> wrote in
news:11**********************@z14g2000cwz.googlegr oups.com:
Larry: Thanks for the quick reply. You are correct, I want to
use the same exact fields, but apply 20 different filters on the
data based on what the person wants to work on. I just don't want
to maintain 20 queries and 20 forms.

I will try your answer as I think it is the easiest and therefore
the most elegant.


I wouldn't maintain any queries at all -- just filter the basic
form.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #9
Steve Jorgensen <no****@nospam.nospam> wrote in
news:43********************************@4ax.com:
On 24 Jun 2005 07:48:46 -0700, "gl******@cox.net"
<gl******@cox.net> wrote:
Larry: Thanks for the quick reply. You are correct, I want to
use the same exact fields, but apply 20 different filters on the
data based on what the person wants to work on. I just don't want
to maintain 20 queries and 20 forms.

I will try your answer as I think it is the easiest and therefore
the most elegant.


Just to add my 2 cents...

I've found that it's not good for the code that launches the form
to be too tightly coupled to -how- the form displays its records.
Thus, rather than pass the criteria using the FilterName or
WhereCondition clauses, I prefer to pass the criteria using
OpenArgs, and let the form build the SQL or apply a filter to
itself during its Open event handler.

One example of where this technique pays off...

You open the same form from 10 different calling procedures, and
now you find you need to present the form data in a subform of the
main form. You can't simply apply the criteria to the main form
because it's not the one bound to the data, and there are now 10
places the code would have to be changed to accomodate the new
master/sub form design. Careful - don't miss one.


Well, that sounds like an ideal situation to have the form's default
recordsource be an empty recordset (or the uneditable single record
I described in another post), and then use public properties of the
form to set the recordsource.

DoCmd.OpenForm "MyForm", , , , , acHidden
Forms!MyForm.WhereClause = "[your criteria here]"

The .WhereClause property of the form would look something like
this:

Property Let WhereClause(strSQL As String)
Dim strRecordsource As String

' assumes module-level constant with the base SELECT/FROM
strRecordsource = c_strRecordsource
strRecordsource = strRecordsource & " WHERE " & strSQL
Me.Recordsource = strRecordsource
Me.Visible = True
End Property

That way you're treating the form as an object, and everything about
the form that needs to know what to do with itself is encapsulated
in the form itself. This could include issues like even passing the
form an argument to display a child record, then having that
property look up the parent record, navigate to it in the parent
form, then display the appropriate child record.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #10
On Fri, 24 Jun 2005 21:49:34 GMT, "David W. Fenton"
<dX********@bway.net.invalid> wrote:
Steve Jorgensen <no****@nospam.nospam> wrote in
news:43********************************@4ax.com :
On 24 Jun 2005 07:48:46 -0700, "gl******@cox.net"
<gl******@cox.net> wrote:
Larry: Thanks for the quick reply. You are correct, I want to
use the same exact fields, but apply 20 different filters on the
data based on what the person wants to work on. I just don't want
to maintain 20 queries and 20 forms.

I will try your answer as I think it is the easiest and therefore
the most elegant.


Just to add my 2 cents...

I've found that it's not good for the code that launches the form
to be too tightly coupled to -how- the form displays its records.
Thus, rather than pass the criteria using the FilterName or
WhereCondition clauses, I prefer to pass the criteria using
OpenArgs, and let the form build the SQL or apply a filter to
itself during its Open event handler.

One example of where this technique pays off...

You open the same form from 10 different calling procedures, and
now you find you need to present the form data in a subform of the
main form. You can't simply apply the criteria to the main form
because it's not the one bound to the data, and there are now 10
places the code would have to be changed to accomodate the new
master/sub form design. Careful - don't miss one.


Well, that sounds like an ideal situation to have the form's default
recordsource be an empty recordset (or the uneditable single record
I described in another post), and then use public properties of the
form to set the recordsource.

DoCmd.OpenForm "MyForm", , , , , acHidden
Forms!MyForm.WhereClause = "[your criteria here]"

The .WhereClause property of the form would look something like
this:

Property Let WhereClause(strSQL As String)
Dim strRecordsource As String

' assumes module-level constant with the base SELECT/FROM
strRecordsource = c_strRecordsource
strRecordsource = strRecordsource & " WHERE " & strSQL
Me.Recordsource = strRecordsource
Me.Visible = True
End Property

That way you're treating the form as an object, and everything about
the form that needs to know what to do with itself is encapsulated
in the form itself. This could include issues like even passing the
form an argument to display a child record, then having that
property look up the parent record, navigate to it in the parent
form, then display the appropriate child record.


Yeah, that's a decent approach. I tend not to couple the an object's
initialization to the setting of the property though. I'd either make a Setup
procedure that takes a where condition (and any other required arguments), or
have a Startup procedure that takes no arguments and is called after setting
the prerequisite form properties.
Nov 13 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CHARLES GANTZ | last post by:
I have an exisiting VC++ 6.0 application. When recompiled into .net, the program works fine, but I would like redo the program to use all the VC++.net functionality. But I want to reuse the...
1
by: Roy | last post by:
Hi all, I need to use a form from one application to another. I can do the followings: 1. Copy the form.vb file to the new project folder and add it to the project as an existing form. 2....
9
by: Alan | last post by:
Using VC++ (1998) compiler with PFE32 editor in Win2K Pro SP4. (DigitalMars CD on order. ) The program (below) instantiates a class and then deletes it. I would have thought that reusing the...
2
by: Luis | last post by:
I have a function sililar to the one below on one of my pages. It puts the value of a field on a form into a variable called FieldName: function checkSomething() { var FieldName =...
4
by: Old Wolf | last post by:
#include <stdio.h> #include <stdarg.h> Is this safe: void foo(const char *fmt, ...) { va_list ap; va_start(ap,fmt);
6
by: kun1he2 | last post by:
Hmm... reusing VB.NET Form dialogs in other VB.NET projects seems very straight forward. However, I'm now trying to reuse these dialogs within an existing C-based app. The VB.NET project has...
3
by: garyusenet | last post by:
Dear Professionals, I have recently been using the wonderful krypton toolkit and am trying to use them in my small hobby application. I include this bit of info as an aside really because i'm...
0
by: davingle | last post by:
I want to reuse an online (NHS) application form for further applications in a smarter way than repeatedly cutting and pasting. Problem is each form comes with a specific title which I can't change...
4
by: jehugaleahsa | last post by:
Hello: Is it me, or is handling the Validating event for every control on a form extremely annoying? It is especially annoying when my business logic repeats most of the validation. Some things...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.