Can you add a button to a report?

  • Thread starter Thread starter Mike D.
  • Start date Start date
M

Mike D.

I made a form so that when you click a button, you see
a "preview report". Most end-users don't have the know-
how to click the small x when done to close the report
preview, and end up closing the whole program.
Is it possible to add a large button on a report?
 
Mike said:
I made a form so that when you click a button, you see
a "preview report". Most end-users don't have the know-
how to click the small x when done to close the report
preview, and end up closing the whole program.
Is it possible to add a large button on a report?


No, report are not active objects and can not support
actions such as a Click event.

User's can be taught to click on the Print Preview tool
bar's Close button or the report's little x, if you use a
big enough 2x4 ;-)
 
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
'**************************************
 
Back
Top