Print Current record

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

Guest

I currently have a form that has a button that will driect the user to a
report. The report is linked to a query that looks for the case number. The
user has to put the case number of the current form to print the record.
Instead of [please enter case number] in the query is there a code to print
the current record in the case number field in the query?

Thanks
Kevin Sebring
 
This question is asked and answered very often. Please search the newsgroup for your answer before posting a new thread in the future...

Button to print specific record
Private Sub cmdPrint_Click()

Dim strWhere As String

If Me.Dirty Then 'Save any edits.

Me.Dirty = False

End If

If Me.NewRecord Then 'Check there is a record to print

MsgBox "Select a record to print"

Else

strWhere = "[ID] = " & Me.[ID]

DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End If

End Sub



Notes: If your primary key is a Text type field (not a Number type field), you need extra quotes: strWhere = "[ID] = """ & Me.[ID] & """"

If you want the report to print without preview, replace acViewPreview with acViewNormal.



See also: http://allenbrowne.com/casu-15.html
 
One option is to set the filter in the query to the field in the form

Select * From TableName Where FieldName = Forms![FormName]![FieldName]

If the field located in a sub form, then try
Select * From TableName Where FieldName =
Forms![FormName]![SubFormControlName].Form![FieldName]

The second option, see this link on "Printing the Record on the Microsoft
Access Form to a Report"

http://www.databasedev.co.uk/report_from_form_record.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top