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
'**************************************