VB Code:
Option Explicit 'ADD REFERENCE TO MS ACCESS XX.X OBJECT LIBRARY 'ADD ONE (1) COMMAND BUTTON (Command1) 'EXAMPLE WILL CREATE A NEW DATABASE AND A NEW REPORT WITH ONE TEXTBOX AND A LINKED LABEL Private Sub Command1_Click() Dim oApp As Access.Application Dim oReport As Access.Report Dim oLabel As Object Dim oTextBox As Object If Dir("D:\RobDog888.mdb", vbArchive Or vbNormal Or vbHidden Or vbReadOnly) <> "" Then Kill "D:\RobDog888.mdb" End If Set oApp = New Access.Application oApp.NewCurrentDatabase "D:\RobDog888.mdb" oApp.Visible = True Set oReport = oApp.CreateReport ' oReport.RecordSource = "qrySomeQuery" oReport.LayoutForPrint = True oReport.Caption = "MyReport" Set oTextBox = oApp.CreateReportControl(oReport.Name, acTextBox, acDetail, "", "", 1560, 1500, 1000, 250) Set oLabel = oApp.CreateReportControl(oReport.Name, acLabel, acDetail, oTextBox.Name, , 500, 1500, 1000, 250) oTextBox.Properties(1).Value = "txtTextBox" oTextBox.Properties(3).Value = "My Text" oLabel.Name = "lblLabel" oLabel.Caption = "My Label" DoCmd.Maximize oApp.RunCommand acCmdPrintPreview 'oReport.Print End Sub





Reply With Quote