Form questions

  • Thread starter Thread starter Bruce
  • Start date Start date
B

Bruce

First, a general question. I have heard that forms are
for entering and modifying records, and should generally
not be printed. Any particular reason for that? The
reason I ask is that I cannot add a print button to a
report, as far as I know. I know I can print from the
toolbar, but I would like to have the print option on the
report itself. No big deal, just curious.
Next question: I have designed a form for listing
documents to be reviewed. When it is completed the record
needs to be saved, and the related report printed. If I
add a print button to the form, it prints all of the
records (reports). If I put a preview report button on
the form, the report can be printed from the report's
toolbar or menu, but the default is to print all records.
I don't want the users to have to choose Selected Record
in the print dialog. How can I handle this?
Possibly related question: If I put Page X of Y in the
report footer, how can I make it so the number of pages is
the number of pages needed to print that record, not the
number for all records?
I expect these are pretty elementary questions, but that
is my skill level at the moment. Thanks.
 
I can help you with the first part of your Q.
Here is how I do it (Thanks to many people in this NG):
The idea is to make a floating toolbar when the report opens:
(You have to translate som text from Norwegian but I think you will
understand)

In a standard module:
'****************************
' Makes a floating menu
Sub AddNewCB()
Dim CBar As CommandBar, CBarCtl As CommandBarControl
On Error GoTo AddNewCB_Err
FjernBar

Set CBar = CommandBars.Add(Name:="Skriv ut eller lukk",
Position:=msoBarFloating)
CBar.Visible = True

Set CBarCtl = CBar.Controls.Add(Type:=msoControlButton)

With CBarCtl
.Caption = " Skriv ut "
.Style = msoButtonCaption
.TooltipText = "Skriv Ut"
.OnAction = "=PrintNow()"
End With

Set CBarCtl3 = CBar.Controls.Add(Type:=msoControlButton)

With CBarCtl3
.Caption = " Velg skriver "
.Style = msoButtonCaption
.BeginGroup = True
.TooltipText = "Velg skriver"
.OnAction = "=ChoosePrint()"
End With


Set CBarCtl2 = CBar.Controls.Add(Type:=msoControlButton)

With CBarCtl2
.Caption = " Lukk "
.Style = msoButtonCaption
.BeginGroup = True
.TooltipText = "Lukk rapporten"
.OnAction = "=LukkRapport()"
End With



Exit Sub

AddNewCB_Err:
MsgBox "Error " & Err.Number & vbCr & Err.Description
Exit Sub

End Sub
'************************
' Removes the floating toolbar
Sub FjernBar()

foundFlag = False
delBars = 0
For Each bar In CommandBars
If (bar.BuiltIn = False) And _
(bar.Visible = True) Then
bar.Delete
foundFlag = True
delBars = delBars + 1
End If
Next bar
For Each bar In CommandBars
If (bar.BuiltIn = False) And _
(bar.Visible = False) Then
bar.Delete
foundFlag = True
delBars = delBars + 1
End If
Next bar

End Sub
'***************************
' Prints the report
Public Function PrintNow()
On Error Resume Next
Dim strRptName
strRptName = Screen.ActiveReport.Name
DoCmd.SelectObject acReport, strRptName, False
DoCmd.PrintOut acPrintAll
End Function

'**************************
'Choose printer
Public Function ChoosePrint()
On Error Resume Next
Dim strRptName
strRptName = Screen.ActiveReport.Name
DoCmd.SelectObject acReport, strRptName, False
DoCmd.RunCommand acCmdPrint
End Function

'***************************
' Close report whitout printing
Public Function LukkRapport()
On Error Resume Next
Dim strRptName
strRptName = Screen.ActiveReport.Name
DoCmd.SelectObject acReport, strRptName, False
DoCmd.RunCommand acCmdClose
End Function


In the module for the report:
'*****************************'
Private Sub Report_Open(Cancel As Integer)
AddNewCB
DoCmd.Maximize
End Sub

Private Sub Report_Close()
FjernBar
DoCmd.Restore
End Sub
'**************************************
 
There is a fairly simple answer to this. I will explain it in terms of
Access 2000, though it should be similar for any access after access'97.

Each record in your database has a unique ID. For purposes of this example
the Unique ID's name property is recordID .

Go into Design View for the form and create a button.
Don't follow any of the wizards if they come up, just click Cancel. This
will leave you with a button on the screen.
Select the button and open the properties window. Change the caption
property as desired.
Select the On Click property under the Event tab.
Click the [...] button that appears next to that property. and select
code builder. A VBA window will open

Paste the following code in between the Sub header and footer - the cursor
should already be in place. Change yourreportname to - well you guessed it.

'--------------------------------------------

Dim DocName As String
Dim LinkCriteria As String

stLinkCriteria = "[recordID]=" & Me![recordID]
stDocName = "yourreportname"
DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

Exit Sub

'---------------------------------------------

This will insure that the reports are filtered to the relevant record and
the page numbering will be adjusted.
 
Thank you. That solved the problem of printing a single
record and having the page numbering work properly.
-----Original Message-----
There is a fairly simple answer to this. I will explain it in terms of
Access 2000, though it should be similar for any access after access'97.

Each record in your database has a unique ID. For purposes of this example
the Unique ID's name property is recordID .

Go into Design View for the form and create a button.
Don't follow any of the wizards if they come up, just click Cancel. This
will leave you with a button on the screen.
Select the button and open the properties window. Change the caption
property as desired.
Select the On Click property under the Event tab.
Click the [...] button that appears next to that property. and select
code builder. A VBA window will open

Paste the following code in between the Sub header and footer - the cursor
should already be in place. Change yourreportname to - well you guessed it.

'--------------------------------------------

Dim DocName As String
Dim LinkCriteria As String

stLinkCriteria = "[recordID]=" & Me![recordID]
stDocName = "yourreportname"
DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

Exit Sub

'---------------------------------------------

This will insure that the reports are filtered to the relevant record and
the page numbering will be adjusted.








First, a general question. I have heard that forms are
for entering and modifying records, and should generally
not be printed. Any particular reason for that? The
reason I ask is that I cannot add a print button to a
report, as far as I know. I know I can print from the
toolbar, but I would like to have the print option on the
report itself. No big deal, just curious.
Next question: I have designed a form for listing
documents to be reviewed. When it is completed the record
needs to be saved, and the related report printed. If I
add a print button to the form, it prints all of the
records (reports). If I put a preview report button on
the form, the report can be printed from the report's
toolbar or menu, but the default is to print all records.
I don't want the users to have to choose Selected Record
in the print dialog. How can I handle this?
Possibly related question: If I put Page X of Y in the
report footer, how can I make it so the number of pages is
the number of pages needed to print that record, not the
number for all records?
I expect these are pretty elementary questions, but that
is my skill level at the moment. Thanks.


.
 
Thank you for your help, but I have to tell you I could
not get it to work. I attached the code to the On Open
event for the report, but I got error messages when I
tried to compile the code, and I could not sort out which
words need to be changed to conform to the names I am
already using. Please remember that I asked this question
in the Getting Started forum, and the script you supplied
is beyond my ability to understand. I like the idea of a
floating toolbar to provide user options on a report, and
I will save your code and look at it again when my skill
level increases.
 
Back
Top