Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening report based on drop down selection

Status
Not open for further replies.

bishman

Programmer
Jun 29, 2003
9
GB
Hi

Here's some Access VBA:

Dim found As Boolean
Dim frm As Form

found = False
For Each frm In Forms
If frm.Name = "SelectType" Then
found = True
End If
Next

strReportType = Forms!SelectType!ReportTypeCombo.Value

Now depending on what has been chosen in the drop down list (ReportTypeCombo), how would I go about opening certain (already existing) reports?

TIA,
Bishman
 
ummmmm - let me see - use the OpenReport method of DoCmd
From Access VBA help:

OpenReport Method
See Also Applies To Example Specifics
The OpenReport method carries out the OpenReport action in Visual Basic.

expression.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs)

expression Required. An expression that returns a DoCmd object.

ReportName Required Variant. A string expression that's the valid name of a report in the current database. If you execute Visual Basic code containing the OpenReport method in a library database, Microsoft Access looks for the report with this name, first in the library database, then in the current database.

View Optional AcView. The view to apply to the specified report.

AcView can be one of these AcView constants.
acViewDesign
acViewNormal default Prints the report immediately.
acViewPivotChart Not supported.
acViewPivotTable Not supported.
acViewPreview

FilterName Optional Variant. A string expression that's the valid name of a query in the current database.

WhereCondition Optional Variant. A string expression that's a valid SQL WHERE clause without the word WHERE.

WindowMode Optional AcWindowMode.

AcWindowMode can be one of these AcWindowMode constants.
acDialog
acHidden
acIcon
acWindowNormal default

OpenArgs Optional Variant. Sets the OpenArgs property.

Remarks
For more information on how the action and its arguments work, see the action topic.

The maximum length of the WhereCondition argument is 32,768 characters (unlike the Where Condition action argument in the Macro window, whose maximum length is 256 characters).

You can leave an optional argument blank in the middle of the syntax, but you must include the argument's comma. If you leave one or more trailing arguments blank, don't use a comma following the last argument you specify.

Example
The following example prints Sales Report while using the existing query Report Filter.

DoCmd.OpenReport "Sales Report", acViewNormal, "Report Filter"

so you would use:
DoCmd.OpenReport strReportType, acViewNormal

Rgds
Geoff
Si hoc legere scis, nimis eruditionis habes
Get the best answers to your questions - faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top