Help! Command buttons in reports

  • Thread starter Thread starter Chris
  • Start date Start date
Hi Chris!

What is it you want to do? Print and close a report from a form?

You can add a cmd-button on a report but it´s only a dummy. You can NOT add
some code or functionality to a cmd in a report. cmd belongs to form´s and
form´s only!

But it is possible to print a report from a form and close it after report
have been printed. But is this what you want to do?

// Niklas
 
I remember I saw at somebody a report having cmd buttons.Do you think that
he was opening in the same time with the report a form containing just the
buttons ?
 
Yes, I think it was a form that was opened or maby a customized Tool Bar.

What is it you want to do?

// Niklas
 
Maybe you are looking for sth like this:

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