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

Generate Report from Form 2

Status
Not open for further replies.

nastar1

Technical User
Nov 1, 2005
122
US
I'd like to have a command button on a Form that would generate a Report of only the data for the current record displayed on the form.

Could use a kick start in how I should get started. I've built a parameter query that prompts for the Primary Key of a record and am building a report from this Query.

I don't want the user to have to respond to the Prompt of the underlying query. Whatever the active record on the form needs to pass the Primary key to the query and generate the Report.

Thanks
 
For the parameter in your query, enter:

forms!formname!fieldname

example

forms!frmClientInfo!txtClientName


Try this.
 
I try to create all report record sources without any criteria. My preferred method is to use code like:
Code:
Dim strWhere as String
strWhere = "1=1 "
If Not IsNull(Me.txtPrimaryKey) Then
   strWhere = strWhere & " AND [PrimaryKeyField] = " & _
       Me.txtPrimaryKey
End If
DoCmd.OpenReport "rptMyRptName", acPreview, , strWhere
If the primary key field is text rather than numeric, try:
Code:
Dim strWhere as String
strWhere = "1=1 "
If Not IsNull(Me.txtPrimaryKey) Then
   strWhere = strWhere & " AND [PrimaryKeyField] = """ & _
       Me.txtPrimaryKey & """ "
End If
DoCmd.OpenReport "rptMyRptName", acPreview, , strWhere



Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top