Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 18th, 2005, 03:12 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Penta,

I have successfully created a report programatically using the below -

CODE STARTS

Option Compare Database
Option Explicit

Private rpt As Report
Private lngCurWidth As Long 'Tracks cumulative width of controls

Const CONSTHEIGHT = 270 'Default values for controls
Const CONSTWIDTH = 2700

Private Sub cmdBuild_Click()
On Error GoTo ErrTrap
'----------------------------
lngCurWidth = 10

'*** REPORT ***
Set rpt = CreateReport
With rpt
    .RecordSource = "qry_SubRecords" 'Set record source
    .PageHeaderSection.Height = 300 'tentar mudar altura do cabeçalho
    .Section("Detail").Height = 265
End With

'*** GROUPING ***
Dim strGrpFld As String
strGrpFld = "Name" 'Change to your grouping level field
CreateGroupLevel rpt.Name, strGrpFld, True, False 'Report,Field,Header,Footer
rpt.Section(5).Height = 265 'Set height of Group Header

'Add group control for 'Name'
CreateTextBox "Name", "txtName", acGroupLevel1Header
'Reset lngCurWidth for Detail controls
lngCurWidth = 10

'*** DETAILS ***
CreateLabel "Field1", "lblField1", acPageHeader, 1000
CreateTextBox "Field1", "txtField1", acDetail, 1000

'Add More Controls
CreateLabel "Field2", "lblField2", acPageHeader
CreateTextBox "Field2", "txtField2", acDetail

'Add More Controls
CreateLabel "Field3", "lblField3", acPageHeader
CreateTextBox "Field3", "txtField3", acDetail

'Add More Controls
CreateLabel "Field4", "lblField4", acPageHeader
CreateTextBox "Field4", "txtField4", acDetail

'*** FORMATTING ***
With rpt
    .Section(0).Height = 280
End With

'----------------------------
ExitTrap:
    'Destroy Report?
    Exit Sub
ErrTrap:
    Select Case Err.Number
        Case Is <> 0
            MsgBox "An unexpected error has occurred: " & Err.Description _
                , vbExclamation + vbOKOnly _
                , "Error " & Err.Number & " occurred" _
                , Err.HelpFile _
                , Err.HelpContext
        Resume ExitTrap

        'Add handled errors here with case

    End Select
End Sub

Private Sub CreateTextBox(ctlSource As String, ctlName As String, lngSection As Integer, Optional lngWidth As Long)
    Dim txt1 As TextBox 'Declare textbox variable

    If lngWidth < 1 Then lngWidth = CONSTWIDTH 'Set default width if not specifieD

    Set txt1 = CreateReportControl(rpt.Name, acTextBox, lngSection, , , lngCurWidth)
    With txt1 'Set ptys
        .Name = ctlName
        .Width = lngWidth
        .ControlSource = ctlSource
        .Height = CONSTHEIGHT
        If lngSection = acGroupLevel1Header Then
            .FontSize = 12
            .FontBold = True
            .Height = CONSTHEIGHT + 100
        End If
    End With
    lngCurWidth = lngCurWidth + txt1.Width + 50 'Store cumulative width of controls including gap
End Sub

Private Sub CreateLabel(strCaption As String, ctlName As String, lngSection As String, Optional lngWidth As Long)
    Dim lbl1 As Label 'Declare label control variable

    If lngWidth < 1 Then lngWidth = CONSTWIDTH 'Set default width if not specified

    Set lbl1 = CreateReportControl(rpt.Name, acLabel, acPageHeader, , , lngCurWidth, , lngWidth)
    With lbl1 'Set ptys
        .Name = ctlName
        .Caption = strCaption
        .Width = 2700
        .Height = CONSTHEIGHT
        .FontBold = True
    End With
End Sub

CODE ENDS

Let us know how you get on,;)

Jon


 
Old May 18th, 2005, 03:13 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 100
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Penta,

Forgot to mention that this is all in a form module and the creation is called by cliking a form command button.

Jon

 
Old May 19th, 2005, 04:53 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for the delay,
Only today i could try ur code.It's working OK.I would not reset the lngCurWidth
after the first CreateTextBox (grouping on field) so the labels wont be on
the same vertical line. What is missing on my target is a break a page code
after each group and i'll have to think about it later.(Translation: try to
find it on the handbook.)
It was a BIG,BIG help what u did, thanks so much again,
Penta :D







Similar Threads
Thread Thread Starter Forum Replies Last Post
creating multiple instances programmatically dcher BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 4 December 28th, 2007 02:21 PM
creating code programmatically mumphis Excel VBA 0 September 2nd, 2005 09:29 AM
Creating a table programmatically Bob Burns ASP.NET 1.0 and 1.1 Basics 2 July 15th, 2004 11:44 AM
Creating report programmatically liliarum BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 July 6th, 2004 09:34 AM
Creating Tables Programmatically stu9820 ASP.NET 1.0 and 1.1 Basics 10 October 22nd, 2003 04:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.