Problem printing form

G

Guest

I have a data input form that I would like to have the end users print for a
quick and dirty copy. I can have them go to print and select current
record(s) but would much rather have them be able to just press a button. I
know how to create a report to print the information but would rather do it
from code so I can use that code on other forms in the future.


I have used the following code but it prints all of the forms. I can not
find any arguments to print the current active record.

stDocName = "frmProHeader"
Set MyForm = Screen.ActiveForm
DoCmd.SelectObject acForm, stDocName, True
DoCmd.PrintOut
DoCmd.SelectObject acForm, MyForm.Name, False

Any Suggestions?
 
D

Douglas J Steele

AFAIK, there isn't any way to do that, largely because forms aren't intended
to be printed.
 
R

Rick B

I would create a report and add a button to your form to print the report.
You can also specify that it should only print the current record.

This issue is addressed pretty often in here. Did you search before posting
a new thread? Here is the code I have shared with others recently...

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
 
G

Guest

Well I found that it can be done and it is quick and easy enough to add to
all forms!

Change the original code below:

stDocName = "frmProHeader"
Set MyForm = Screen.ActiveForm
DoCmd.SelectObject acForm, stDocName, True
DoCmd.PrintOut
DoCmd.SelectObject acForm, MyForm.Name, False

To:
DoCmd.PrintOut acSelection

You lose the ability to select the active record when you use the
SelectObject method.
 

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

Top