Form Printing

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

Guest

Good morning,

I have a form where users can select a client from a combo box to show the
records of that client. On the same form, I have a print button where people
can click the button to print the records of the clients they desire.

What is happening is when people click on the print button, it will prompt
the user to type in the client #. Then print the client's records. I don't
want the database to prompt for the client # for the user to type in.
Instead, I want it to print a report (with prompting) based on the client
that user has selected on the form.

How can I connect the form and the report so that it would print without
prompting? I have a report created for that print button. I don't want to
print the actual form.

Thanks.
 
First, good job on building a report and not printing the form. that is the
correct way to do it, but many try to print the form then get frustrated
when it looks bad.

Here is some code that will do what you want. You may need to modify it
slightly...

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
 
Back
Top