Observação
O acesso a essa página exige autorização. Você pode tentar entrar ou alterar diretórios.
O acesso a essa página exige autorização. Você pode tentar alterar os diretórios.
Um objeto Report refere-se a um relatório específico do Microsoft Access.
Comentários
Um objeto Relatório é um membro da coleção Relatórios , que é uma coleção de todos os relatórios atualmente abertos. Dentro da coleção de relatórios, os relatórios individuais são indexados começando com zero. Veja um objeto de Relatório individual na coleção Relatórios ao referenciar o relatório por nome ou ao consultar o respetivo índice na coleção. Se o nome do relatório incluir um espaço, o nome deverá estar entre colchetes ([ ]).
| Sintaxe | Exemplo |
|---|---|
| Relatórios! nome do relatório | Relatórios! OrderReport |
| Relatórios! [nome do relatório] | Reports![Order Report] |
| Relatórios("nome do relatório") | Reports("OrderReport") |
| Relatórios(índice) | Reports(0) |
Observação
[!OBSERVAçãO] Cada objeto de relatório tem um conjunto de controles, que contém todos os controles do relatório. Veja um controlo num relatório ao referenciar implicitamente ou explicitamente a coleção Controlos . Seu código será mais rápido se você fizer referencia à coleção Controls implicitamente. Os exemplos a seguir mostram duas das maneiras de que se referir a um controle chamado NewData em um relatório denominado OrderReport.
' Implicit reference.
Reports!OrderReport!NewData
' Explicit reference.
Reports!OrderReport.Controls!NewData
Exemplo
O exemplo seguinte mostra como utilizar o evento NoData de um relatório para impedir a abertura do relatório quando não existem dados a apresentar.
Private Sub Report_NoData(Cancel As Integer)
'Add code here that will be executed if no data
'was returned by the Report's RecordSource
MsgBox "No customers ordered this product this month. " & _
"The report will now close."
Cancel = True
End Sub
O exemplo a seguir mostra como usar o evento Page para adicionar uma marca d'água a um relatório antes que ele seja impresso.
Private Sub Report_Page()
Dim strWatermarkText As String
Dim sizeHor As Single
Dim sizeVer As Single
#If RUN_PAGE_EVENT = True Then
With Me
'// Print page border
Me.Line (0, 0)-(.ScaleWidth - 1, .ScaleHeight - 1), vbBlack, B
'// Print watermark
strWatermarkText = "Confidential"
.ScaleMode = 3
.FontName = "Segoe UI"
.FontSize = 48
.ForeColor = RGB(255, 0, 0)
'// Calculate text metrics
sizeHor = .TextWidth(strWatermarkText)
sizeVer = .TextHeight(strWatermarkText)
'// Set the print location
.CurrentX = (.ScaleWidth / 2) - (sizeHor / 2)
.CurrentY = (.ScaleHeight / 2) - (sizeVer / 2)
'// Print the watermark
.Print strWatermarkText
End With
#End If
End Sub
O exemplo a seguir mostra como definir a propriedade BackColor de um controle com base em seu valor.
Private Sub SetControlFormatting()
If (Me.AvgOfRating >= 8) Then
Me.AvgOfRating.BackColor = vbGreen
ElseIf (Me.AvgOfRating >= 5) Then
Me.AvgOfRating.BackColor = vbYellow
Else
Me.AvgOfRating.BackColor = vbRed
End If
End Sub
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
' size the width of the rectangle
Dim lngOffset As Long
lngOffset = (Me.boxInside.Left - Me.boxOutside.Left) * 2
Me.boxInside.Width = (Me.boxOutside.Width * (Me.AvgOfRating / 10)) - lngOffset
' do conditional formatting for the control in print preview
SetControlFormatting
End Sub
Private Sub Detail_Paint()
' do conditional formatting for the control in report view
SetControlFormatting
End Sub
O exemplo a seguir mostra como formatar um relatório para mostrar as barras de progresso. O exemplo usa um par de controles de retângulo, boxInside e boxOutside, para criar uma barra de progresso com base no valor de AvgOfRating. As barras de progresso são visíveis apenas quando o relatório é aberto no modo Visualizar impressão ou ela é impressa.
Private Sub Report_Load()
If (Me.CurrentView = AcCurrentView.acCurViewPreview) Then
Me.boxInside.Visible = True
Me.boxOutside.Visible = True
Else
Me.boxInside.Visible = False
Me.boxOutside.Visible = False
End If
End Sub
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
' size the width of the rectangle
Dim lngOffset As Long
lngOffset = (Me.boxInside.Left - Me.boxOutside.Left) * 2
Me.boxInside.Width = (Me.boxOutside.Width * (Me.AvgOfRating / 10)) - lngOffset
' do conditional formatting for the control in print preview
SetControlFormatting
End Sub
Eventos
- Activate
- ApplyFilter
- Click
- Close
- Current
- DblClick
- Deactivate
- Erro
- Filter
- GotFocus
- KeyDown
- KeyPress
- KeyUp
- Load
- LostFocus
- MouseDown
- MouseMove
- MouseUp
- MouseWheel
- NoData
- Open
- Página
- Resize
- Timer
- Unload
Métodos
Propriedades
- ActiveControl
- AllowLayoutView
- AllowReportView
- Application
- AutoCenter
- AutoResize
- BorderStyle
- Caption
- CloseButton
- ControlBox
- Controls
- Count
- CurrentRecord
- CurrentView
- CurrentX
- CurrentY
- Cycle
- DateGrouping
- DefaultControl
- DefaultView
- Dirty
- DisplayOnSharePointSite
- DrawMode
- DrawStyle
- DrawWidth
- FastLaserPrinting
- FillColor
- FillStyle
- Filtrar
- FilterOn
- FilterOnLoad
- FitToPage
- FontBold
- FontItalic
- FontName
- FontSize
- FontUnderline
- ForeColor
- FormatCount
- GridX
- GridY
- GroupLevel
- GrpKeepTogether
- HasData
- HasModule
- Height
- HelpContextId
- HelpFile
- Hwnd
- InputParameters
- KeyPreview
- LayoutForPrint
- Left
- MenuBar
- MinMaxButtons
- Modal
- Module
- MouseWheel
- Moveable
- MoveLayout
- Nome
- NextRecord
- OnActivate
- OnApplyFilter
- OnClick
- OnClose
- OnCurrent
- OnDblClick
- OnDeactivate
- OnError
- OnFilter
- OnGotFocus
- OnKeyDown
- OnKeyPress
- OnKeyUp
- OnLoad
- OnLostFocus
- OnMouseDown
- OnMouseMove
- OnMouseUp
- OnNoData
- OnOpen
- OnPage
- OnResize
- OnTimer
- OnUnload
- OpenArgs
- OrderBy
- OrderByOn
- OrderByOnLoad
- Orientation
- Página
- PageFooter
- PageHeader
- Pages
- Painting
- PaintPalette
- PaletteSource
- Parent
- Picture
- PictureAlignment
- PictureData
- PicturePages
- PicturePalette
- PictureSizeMode
- PictureTiling
- PictureType
- PopUp
- PrintCount
- Printer
- PrintSection
- Properties
- PrtDevMode
- PrtDevNames
- PrtMip
- RecordLocks
- Recordset
- RecordSource
- RecordSourceQualifier
- Relatório
- RibbonName
- ScaleHeight
- ScaleLeft
- ScaleMode
- ScaleTop
- ScaleWidth
- ScrollBars
- Section
- ServerFilter
- Forma
- ShortcutMenuBar
- ShowPageMargins
- Tag
- TimerInterval
- Toolbar
- Top
- UseDefaultPrinter
- Visible
- Width
- WindowHeight
- WindowLeft
- WindowTop
- WindowWidth
Confira também
Suporte e comentários
Tem dúvidas ou quer enviar comentários sobre o VBA para Office ou sobre esta documentação? Confira Suporte e comentários sobre o VBA para Office a fim de obter orientação sobre as maneiras pelas quais você pode receber suporte e fornecer comentários.