Printing a form

V

Veli Izzet

Hi all,

I want to print a form, but when I use "Print a Form" button created
with the wizard;

1- I cannot choose printer,
2- I cannot choose layout& size,

Can these be controlled?

Thanks for answers
 
A

Allen Browne

Printing a form generally doesn't work very well. It's best to create a
report, and print that.

With either a form or report, you can open in design view, and choose Page
Setup from the File menu. There you can set the margins, page size,
orientation, and the printer to use for printing this object (Page tab.)
When you save the design, it will remember the settings for later.

Chaning the orientation, margins, and papersize at runtime is a rather
messy, so avoid that if you can. If you need to go that route, start by
reading this chapter by Ken Getz:
http://www.microsoft.com/AccessDev/Articles/GetzCh10.HTM

If you need to let the end-user choose one of their printers to send the
report to and have the report remember that, see:
Printer Selection Utility
at:
http://allenbrowne.com/AppPrintMgt.html
Works with Access 2002 and 2003 only, but has a link to Albert Kallal's
utilities for Access 97 and 2000.
 
V

Veli Izzet

Thanks, the forms I want to print are based on somewhat complex queries,
including more than one subforms, so I thought maybe I could get away
with a quick and dirty way, instead of trying to work out that queries etc.

Thanks for the info..
 
V

Veli Izzet

Hi Allen,

To print via a report from the form I need to pass values of two
controls from the form to the report. (Actually it is going to be kind
of an invoice)

I will put a button to the form, that button will invoke a report based
on a query. Two items from this query must be parametric.

How can I do this?
 
A

Allen Browne

You could put a couple of unbound controls on the report, and a command
button to open the report:

This kind of thing:
Dim strWhere As String
strWhere = "(InvoiceID = " & Nz(Me.InvoiceID,0) & ") AND (City = """ &
Me.City & """)"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere

If you prefer, you can use parameters in the query, and Access will ask for
values when the report runs.

There's an example of how to do this with dates in this article:
http://allenbrowne.com/casu-08.html
 
V

Veli Izzet

Allen, I'm confused.

1- If I put two parameters in the query for fields [BelgeNo] (Text field
like B-0001, etc) and [MTIsim] (Text field again), I have no problem.

When I write the following (The button is Command72, and F1 and F2 are
two unbound controls in the report, I am asked what F1 is, what F2 is
and also what B is (The same query without the parameters, and there is
no B anywhere??????)

The data to be passed to the report is in the controls BelgeNo and Combo14.

When I use """'s instead of ", the code gives an error even before
closing the event procedure window.

What am I doing wrong?

Thanks for your help...

Private Sub Command72_Click()
On Error GoTo Err_Command72_Click

Dim strWhere As String
Dim stDocName As String

strWhere = "(F1 =" & Me.BelgeNo & ") AND F2=" &Me.Combo14&)"


stDocName = "Teslimat Belgesi"

DoCmd.OpenReport stDocName, acPreview, , strWhere

Exit_Command72_Click:
Exit Sub

Err_Command72_Click:
MsgBox Err.Description
Resume Exit_Command72_Click

End Sub
 
A

Allen Browne

You lost me with:
F1 and F2 are two unbound controls in the report
Filtering on a control that is not bound to a field doesn't sound
productive.

The extra quotes are needed as the delimiters for the text type field.
If you Debug.Print strWhere, you should see a string containing something
like this:
([F1] ="fred") AND ([F2] = "betty")
--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Veli Izzet said:
Allen, I'm confused.

1- If I put two parameters in the query for fields [BelgeNo] (Text field
like B-0001, etc) and [MTIsim] (Text field again), I have no problem.

When I write the following (The button is Command72, and F1 and F2 are two
unbound controls in the report, I am asked what F1 is, what F2 is and also
what B is (The same query without the parameters, and there is no B
anywhere??????)

The data to be passed to the report is in the controls BelgeNo and
Combo14.

When I use """'s instead of ", the code gives an error even before closing
the event procedure window.

What am I doing wrong?

Thanks for your help...

Private Sub Command72_Click()
On Error GoTo Err_Command72_Click

Dim strWhere As String
Dim stDocName As String

strWhere = "(F1 =" & Me.BelgeNo & ") AND F2=" &Me.Combo14&)"


stDocName = "Teslimat Belgesi"

DoCmd.OpenReport stDocName, acPreview, , strWhere

Exit_Command72_Click:
Exit Sub

Err_Command72_Click:
MsgBox Err.Description
Resume Exit_Command72_Click

End Sub





Allen said:
You could put a couple of unbound controls on the report, and a command
button to open the report:

This kind of thing:
Dim strWhere As String
strWhere = "(InvoiceID = " & Nz(Me.InvoiceID,0) & ") AND (City = """
& Me.City & """)"
DoCmd.OpenReport "Report1", acViewPreview, , strWhere

If you prefer, you can use parameters in the query, and Access will ask
for values when the report runs.

There's an example of how to do this with dates in this article:
http://allenbrowne.com/casu-08.html
 
V

Veli Izzet

Hi,

I changed the strWhere to:

strWhere = "[BelgeNo] =" & """Me.BelgeNo""" & " AND [MTIsim]=" &
"""Me.Combo14"""

F1 & F2 became bound controls to BelgeNo & MTIsim.

Now, I do not get any messages etc, and the report opens, but it cannot
find the MTIsim and BelgeNo, so the report is blank..
 
V

Veli Izzet

Allen,

You said in your first reply, that I should put some unbound controls on
the form, what is that for?
 
A

Allen Browne

The unbound controls are where the user can enter the values to match, such
as the names Fred and Betty in the example.

If the report returns no values:
- Did you mean OR instead of AND?

- Is the value being entered actually the stored value, or do you have a
combo box in your table, created with the lookup wizard so it lies to you
about what is actullay stored there? More on this:
http://www.mvps.org/access/lookupfields.htm

Print the WhereCondition string to the Immediate Window, i.e.:
Debug.Print strWhere
Then try creating a query that uses that condition, to what is returned.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Veli Izzet said:
You said in your first reply, that I should put some unbound controls on
the form, what is that for?


Allen said:
You lost me with:
F1 and F2 are two unbound controls in the report
Filtering on a control that is not bound to a field doesn't sound
productive.

The extra quotes are needed as the delimiters for the text type field.
If you Debug.Print strWhere, you should see a string containing something
like this:
([F1] ="fred") AND ([F2] = "betty")
 
V

Veli Izzet

Thanks for all the help,

OR or AND is not a problem.

However I have a combobox, I will check the link, there may be a
problem there, I also think I have a hint.

I tried Debug.Print strWhere but nothing came out. I was in the form,
pushed the button, no debug info came out anywhere?
 
A

Allen Browne

The line of code should go into the event procedure.

The output should appear in the Immediate Window (Ctrl+G)
 
Top