Form to feed parameters

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

Guest

I have 4-5 reports which require the same kind of criteria. I have one form
which feeds criteria to one of these and then produces the report. How can I
make the form dynamic enough to be able to select a report, feed the criteria
and then produce any one of these reports.
 
This is a continuation of my question. I attempted this:
In the form, I created a list box which is linked to a table that contains
the names of all reports. On the 'OK' button of this form, I have added 'on
click' event property which has a macro which opens a report. The name of
this report is derived from the value in the list box. But when I click the
OK button on this form, it says:
"The report name '[Forms]![myForm]![lstReports] is either misspelled or does
not exist"
Will this approach work?
 
I create a table of reports that has the actual report name and a more user
friendly report title. This table becomes the Row Source of a list box on
the form. I then use text boxes and other controls for users to enter or
select the criteria they want for the selected report. Double-clicking the
list box or clicking a command button runs code that builds a "where clause"
to use in the DoCmd.OpenReport method.

Dim strWhere as String
Dim strReportName as String
strReportName = Me.lboReports
strWhere = "1=1 "
If Not IsNull(Me.txtStart) Then
strWhere = strWhere & " AND [SaleDate] >=#" & Me.txtStart & "# "
End If
If Not IsNull(Me.txtEnd) Then
strWhere = strWhere & " AND [SaleDate] <=#" & Me.txtEnd & "# "
End If
'other similar code to build the where clause
DoCmd.OpenReport strReportName, acPreview, , strWhere
 
I dont know any Visual Basic and I try to avoid it if I can. Please let me
know whats wrong with the macro approach question that I had initially
posted. Thanks.

Duane Hookom said:
I create a table of reports that has the actual report name and a more user
friendly report title. This table becomes the Row Source of a list box on
the form. I then use text boxes and other controls for users to enter or
select the criteria they want for the selected report. Double-clicking the
list box or clicking a command button runs code that builds a "where clause"
to use in the DoCmd.OpenReport method.

Dim strWhere as String
Dim strReportName as String
strReportName = Me.lboReports
strWhere = "1=1 "
If Not IsNull(Me.txtStart) Then
strWhere = strWhere & " AND [SaleDate] >=#" & Me.txtStart & "# "
End If
If Not IsNull(Me.txtEnd) Then
strWhere = strWhere & " AND [SaleDate] <=#" & Me.txtEnd & "# "
End If
'other similar code to build the where clause
DoCmd.OpenReport strReportName, acPreview, , strWhere


--
Duane Hookom
MS Access MVP


neeraj said:
I have 4-5 reports which require the same kind of criteria. I have one form
which feeds criteria to one of these and then produces the report. How can
I
make the form dynamic enough to be able to select a report, feed the
criteria
and then produce any one of these reports.
 
I'm not sure what previous posting you are referring to that used macros. I
know very little about macros and much prefer working with code which I
believe is much more flexible and robust.

--
Duane Hookom
MS Access MVP


neeraj said:
I dont know any Visual Basic and I try to avoid it if I can. Please let me
know whats wrong with the macro approach question that I had initially
posted. Thanks.

Duane Hookom said:
I create a table of reports that has the actual report name and a more
user
friendly report title. This table becomes the Row Source of a list box on
the form. I then use text boxes and other controls for users to enter or
select the criteria they want for the selected report. Double-clicking
the
list box or clicking a command button runs code that builds a "where
clause"
to use in the DoCmd.OpenReport method.

Dim strWhere as String
Dim strReportName as String
strReportName = Me.lboReports
strWhere = "1=1 "
If Not IsNull(Me.txtStart) Then
strWhere = strWhere & " AND [SaleDate] >=#" & Me.txtStart & "# "
End If
If Not IsNull(Me.txtEnd) Then
strWhere = strWhere & " AND [SaleDate] <=#" & Me.txtEnd & "# "
End If
'other similar code to build the where clause
DoCmd.OpenReport strReportName, acPreview, , strWhere


--
Duane Hookom
MS Access MVP


neeraj said:
I have 4-5 reports which require the same kind of criteria. I have one
form
which feeds criteria to one of these and then produces the report. How
can
I
make the form dynamic enough to be able to select a report, feed the
criteria
and then produce any one of these reports.
 
I will try your code but I will additional help. These are my exact
requirements.
I have created a form which accepts the following criteria: Enter Start
Date, Enter End Date, Supervisor Name, Manager name. I have 4 reports which
accept all the 4 criteria. I have tested this form on one report and it works
fine. On clicking the Ok button on this form, this report gets opened
according to the criteria fed in. As I had written in my second posting, I
have created a list box in this form but now I have a value list here
containing the names of all the reports. Can you give me the exact code so
that I can select the report from the list box, pass the criteria, press the
OK button and open that report

Duane Hookom said:
I'm not sure what previous posting you are referring to that used macros. I
know very little about macros and much prefer working with code which I
believe is much more flexible and robust.

--
Duane Hookom
MS Access MVP


neeraj said:
I dont know any Visual Basic and I try to avoid it if I can. Please let me
know whats wrong with the macro approach question that I had initially
posted. Thanks.

Duane Hookom said:
I create a table of reports that has the actual report name and a more
user
friendly report title. This table becomes the Row Source of a list box on
the form. I then use text boxes and other controls for users to enter or
select the criteria they want for the selected report. Double-clicking
the
list box or clicking a command button runs code that builds a "where
clause"
to use in the DoCmd.OpenReport method.

Dim strWhere as String
Dim strReportName as String
strReportName = Me.lboReports
strWhere = "1=1 "
If Not IsNull(Me.txtStart) Then
strWhere = strWhere & " AND [SaleDate] >=#" & Me.txtStart & "# "
End If
If Not IsNull(Me.txtEnd) Then
strWhere = strWhere & " AND [SaleDate] <=#" & Me.txtEnd & "# "
End If
'other similar code to build the where clause
DoCmd.OpenReport strReportName, acPreview, , strWhere


--
Duane Hookom
MS Access MVP


I have 4-5 reports which require the same kind of criteria. I have one
form
which feeds criteria to one of these and then produces the report. How
can
I
make the form dynamic enough to be able to select a report, feed the
criteria
and then produce any one of these reports.
 
1) what is the name of your list box?
2) how do your reports "accept" the criteria?
3) consider using a table of reports rather than a value list. This would be
much easier to maintain
4) are these your control names:"Enter Start Date", "Enter End Date",...?
5) does the report's control source have the criteria included or do you
want to pass the criteria in the Where Clause?
6) what are the names of the fields in the report record sources that
correspond with each of your 4 criteria?

--
Duane Hookom
MS Access MVP


neeraj said:
I will try your code but I will additional help. These are my exact
requirements.
I have created a form which accepts the following criteria: Enter Start
Date, Enter End Date, Supervisor Name, Manager name. I have 4 reports
which
accept all the 4 criteria. I have tested this form on one report and it
works
fine. On clicking the Ok button on this form, this report gets opened
according to the criteria fed in. As I had written in my second posting, I
have created a list box in this form but now I have a value list here
containing the names of all the reports. Can you give me the exact code so
that I can select the report from the list box, pass the criteria, press
the
OK button and open that report

Duane Hookom said:
I'm not sure what previous posting you are referring to that used macros.
I
know very little about macros and much prefer working with code which I
believe is much more flexible and robust.

--
Duane Hookom
MS Access MVP


neeraj said:
I dont know any Visual Basic and I try to avoid it if I can. Please let
me
know whats wrong with the macro approach question that I had initially
posted. Thanks.

:

I create a table of reports that has the actual report name and a more
user
friendly report title. This table becomes the Row Source of a list box
on
the form. I then use text boxes and other controls for users to enter
or
select the criteria they want for the selected report. Double-clicking
the
list box or clicking a command button runs code that builds a "where
clause"
to use in the DoCmd.OpenReport method.

Dim strWhere as String
Dim strReportName as String
strReportName = Me.lboReports
strWhere = "1=1 "
If Not IsNull(Me.txtStart) Then
strWhere = strWhere & " AND [SaleDate] >=#" & Me.txtStart & "# "
End If
If Not IsNull(Me.txtEnd) Then
strWhere = strWhere & " AND [SaleDate] <=#" & Me.txtEnd & "# "
End If
'other similar code to build the where clause
DoCmd.OpenReport strReportName, acPreview, , strWhere


--
Duane Hookom
MS Access MVP


I have 4-5 reports which require the same kind of criteria. I have
one
form
which feeds criteria to one of these and then produces the report.
How
can
I
make the form dynamic enough to be able to select a report, feed the
criteria
and then produce any one of these reports.
 
Here are the answers in the same order as your questions:
1) lstReports
2) Each report has an underlying parameter query. The parameters come from
the values inputted in the form. For example, one criteria in my query is
[Forms]![Dialog Box - Report - New]![cboManager] where "Dialog Box - Report -
New" is the name of my form and "cboManager" is the name of the combo box for
manager name in that form.
3) OK. I will do a table of reports. Is there any field required other than
the report name as it appears in the object list in my database window
4)Yes, these are the label names for my controls on my form that are feeding
the parameter query. I have got one list box control for selecting a report
name, 2 combo boxes one each for selecting manager name and supervisor name
nad 2 text boxes one each for start date and end date
5) and 6) I dont know what you mean by control source but each of my
reports' record source is a different parameter query
Let me know if you have more questions.



Duane Hookom said:
1) what is the name of your list box?
2) how do your reports "accept" the criteria?
3) consider using a table of reports rather than a value list. This would be
much easier to maintain
4) are these your control names:"Enter Start Date", "Enter End Date",...?
5) does the report's control source have the criteria included or do you
want to pass the criteria in the Where Clause?
6) what are the names of the fields in the report record sources that
correspond with each of your 4 criteria?

--
Duane Hookom
MS Access MVP


neeraj said:
I will try your code but I will additional help. These are my exact
requirements.
I have created a form which accepts the following criteria: Enter Start
Date, Enter End Date, Supervisor Name, Manager name. I have 4 reports
which
accept all the 4 criteria. I have tested this form on one report and it
works
fine. On clicking the Ok button on this form, this report gets opened
according to the criteria fed in. As I had written in my second posting, I
have created a list box in this form but now I have a value list here
containing the names of all the reports. Can you give me the exact code so
that I can select the report from the list box, pass the criteria, press
the
OK button and open that report

Duane Hookom said:
I'm not sure what previous posting you are referring to that used macros.
I
know very little about macros and much prefer working with code which I
believe is much more flexible and robust.

--
Duane Hookom
MS Access MVP


I dont know any Visual Basic and I try to avoid it if I can. Please let
me
know whats wrong with the macro approach question that I had initially
posted. Thanks.

:

I create a table of reports that has the actual report name and a more
user
friendly report title. This table becomes the Row Source of a list box
on
the form. I then use text boxes and other controls for users to enter
or
select the criteria they want for the selected report. Double-clicking
the
list box or clicking a command button runs code that builds a "where
clause"
to use in the DoCmd.OpenReport method.

Dim strWhere as String
Dim strReportName as String
strReportName = Me.lboReports
strWhere = "1=1 "
If Not IsNull(Me.txtStart) Then
strWhere = strWhere & " AND [SaleDate] >=#" & Me.txtStart & "# "
End If
If Not IsNull(Me.txtEnd) Then
strWhere = strWhere & " AND [SaleDate] <=#" & Me.txtEnd & "# "
End If
'other similar code to build the where clause
DoCmd.OpenReport strReportName, acPreview, , strWhere


--
Duane Hookom
MS Access MVP


I have 4-5 reports which require the same kind of criteria. I have
one
form
which feeds criteria to one of these and then produces the report.
How
can
I
make the form dynamic enough to be able to select a report, feed the
criteria
and then produce any one of these reports.
 
It sounds like you don't need to pass a Where clause to your OpenReport
method since your criteria for your reports is already defined in the
report's record source. This should be all you need

Dim strReportName as String
strReportName = Me.lstReports
DoCmd.OpenReport strReportName, acPreview

Once you have this working, you might want to consider removing the
Forms!...!... from the report record sources and use the Where Clause in
DoCmd.OpenReport.
--
Duane Hookom
MS Access MVP


neeraj said:
Here are the answers in the same order as your questions:
1) lstReports
2) Each report has an underlying parameter query. The parameters come from
the values inputted in the form. For example, one criteria in my query is
[Forms]![Dialog Box - Report - New]![cboManager] where "Dialog Box -
Report -
New" is the name of my form and "cboManager" is the name of the combo box
for
manager name in that form.
3) OK. I will do a table of reports. Is there any field required other
than
the report name as it appears in the object list in my database window
4)Yes, these are the label names for my controls on my form that are
feeding
the parameter query. I have got one list box control for selecting a
report
name, 2 combo boxes one each for selecting manager name and supervisor
name
nad 2 text boxes one each for start date and end date
5) and 6) I dont know what you mean by control source but each of my
reports' record source is a different parameter query
Let me know if you have more questions.



Duane Hookom said:
1) what is the name of your list box?
2) how do your reports "accept" the criteria?
3) consider using a table of reports rather than a value list. This would
be
much easier to maintain
4) are these your control names:"Enter Start Date", "Enter End Date",...?
5) does the report's control source have the criteria included or do you
want to pass the criteria in the Where Clause?
6) what are the names of the fields in the report record sources that
correspond with each of your 4 criteria?

--
Duane Hookom
MS Access MVP


neeraj said:
I will try your code but I will additional help. These are my exact
requirements.
I have created a form which accepts the following criteria: Enter Start
Date, Enter End Date, Supervisor Name, Manager name. I have 4 reports
which
accept all the 4 criteria. I have tested this form on one report and it
works
fine. On clicking the Ok button on this form, this report gets opened
according to the criteria fed in. As I had written in my second
posting, I
have created a list box in this form but now I have a value list here
containing the names of all the reports. Can you give me the exact code
so
that I can select the report from the list box, pass the criteria,
press
the
OK button and open that report

:

I'm not sure what previous posting you are referring to that used
macros.
I
know very little about macros and much prefer working with code which
I
believe is much more flexible and robust.

--
Duane Hookom
MS Access MVP


I dont know any Visual Basic and I try to avoid it if I can. Please
let
me
know whats wrong with the macro approach question that I had
initially
posted. Thanks.

:

I create a table of reports that has the actual report name and a
more
user
friendly report title. This table becomes the Row Source of a list
box
on
the form. I then use text boxes and other controls for users to
enter
or
select the criteria they want for the selected report.
Double-clicking
the
list box or clicking a command button runs code that builds a
"where
clause"
to use in the DoCmd.OpenReport method.

Dim strWhere as String
Dim strReportName as String
strReportName = Me.lboReports
strWhere = "1=1 "
If Not IsNull(Me.txtStart) Then
strWhere = strWhere & " AND [SaleDate] >=#" & Me.txtStart & "#
"
End If
If Not IsNull(Me.txtEnd) Then
strWhere = strWhere & " AND [SaleDate] <=#" & Me.txtEnd & "# "
End If
'other similar code to build the where clause
DoCmd.OpenReport strReportName, acPreview, , strWhere


--
Duane Hookom
MS Access MVP


I have 4-5 reports which require the same kind of criteria. I have
one
form
which feeds criteria to one of these and then produces the
report.
How
can
I
make the form dynamic enough to be able to select a report, feed
the
criteria
and then produce any one of these reports.
 
Back
Top