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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing components properties from a general sub 3

Status
Not open for further replies.

waterhorse2

Programmer
Apr 10, 2006
5
US
I am an experienced developer but don't know certain basic syntaxes for VBA.

I have button on a form whose Click event reads data from controls on the form and opens a report with a whereCondition built from the data.

I want be able to launch multiple reports (selected by radio buttons) from this same for with the same button so I want to modularize by moving some of the code from the Click event to individual subs for each report. I have tried a sub with a parameter (FormName As Form) but can't get the calling syntax in the Click event.

Direct answers, references or suggestions of alternate methods would be appreciated.

TIA,

Paul Scott
 
Please provide sample of your code, there is lots of ways to do this.

Private Sub Command24_Click()
Dim strWhere As String
strWhere = "LastName = 'Jones'"
Call openFilteredReport("rptOne", strWhere)
End Sub

Public Sub openFilteredReport(frmName As String, strWhere As String)
DoCmd.OpenReport frmName, acViewPreview, , strWhere
End Sub
 
I guess my variable should read "rptName" not "frmName" in this example
 
outside of MajP's code, working,
your argument frmName As Form, is probably the wrong datatype.
other than thaT, your existing code may have worked.

If I may, i'm going to elaborate a bit, on MajP's code.
________________________________________________
Private Sub Command24_Click()
Dim strWhere As String
Dim strReport As String

Select case optReport
Case 1: strReport = "rptContact"
strWhere = "LastName = 'Jones'"
Case 2: strReport = "rptOffice"
strWhere = "Office = '24 Ridgeway'"
Case 3: strReport = "rptSales"
strWhere = "Sale = > 2500"
Case 4: strReport = "rptDues"
strWhere = "Invoiced <= #3/3/06#"
End SElect


Call openFilteredReport(strReport, strWhere)
End Sub
___________________________________________________
Public Sub openFilteredReport(strReport As String, strWhere As String)
DoCmd.OpenReport frmName, acViewPreview, , strWhere
End Sub
____________________________________________

Those 2 subs, should handle all your reports,
values for strWhere can be fields on your form...

strWhere = "Country ='" & Me.txtCountry & "'"


 
How are ya waterhorse2 . . .

For listboxes have a look at the following properties
[ol][li]Multiselect[/li]
[li]ItemsSelected[/li][/ol]
You could enumerate thru multiple reports with one shot!

Your Thoughts? . . .

Calvin.gif
See Ya! . . . . . .
 
Thank you all. What I learned is that most of you would pass the name of the form as a string rather than pass a reference to the form as I might have done in Delphi or C++ Builder. That will allow me to get whatever data I need for a particular report from the appropriate controls on the form. The report name (string) can be either hard coded in the particular report sub or possibly put in some global storage.

The multi-select doesn't seem to fit the different kinds of reports.

Thanks again,

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top