ColdTeck
ColdTeck

Reputation: 143

Reports in Access 2010 Building with VBA

Ok So I have some questions about VBA Syntax to Build Access Report.

I know of the following functions to insert information CreateReportControl Function, and to delete information DeleteReportControl, and even to modify sections using section
EX: rpt.section(acDetail).Height=0.

  1. I want to know how to toggle off the page header and footer, not just set Visable to False. I want it so it cannot be seen in Design View.

  2. How to duplicate a report in Vba and assign it a new name / add a Sub Report to a main report and move it's placement around. Or at lease duplicate it and leave it open because I have a code the renames it as shown here:

    Public Function GetUniqueReportName() As String
    Dim intCounter As Integer
    Dim blnIsUnique As Boolean
    Dim rpt As Object
    
      For intCounter = 1 To 256
          GetUniqueReportName = "SubReport_" & Format(intCounter, "0000")
          blnIsUnique = True
          For Each rpt In CurrentProject.AllReports
              If rpt.Name = GetUniqueReportName Then blnIsUnique = False
          Next
          If blnIsUnique Then Exit Function
     Next
    
     GetUniqueReportName = ""
     End Function
    
  3. Also is there any more functions that would help me build a Access report via VBA, you don't have to explain what they do I just want to know what they are so I can search for them directly because there is not a lot of information on the web on how to do this.

All this information would be of much help, and I am under the assumption that many other people could use this information as well as there is not a lot on this subject. Thanks in advance! :) If you cant answer all the questions that's ok any information at this point is a bonus.

Upvotes: 2

Views: 7892

Answers (1)

jacouh
jacouh

Reputation: 8741

III. This will create rptTmp by calling rptCreateTmpReportSimple():

Function rptCreateTmpReportSimple()
'
  Dim lLeft As Long, lTop As Long, lWidth As Long, lHeight As Long
'
  Dim strFld As String, strRecordSource As String
  Dim strRpt As String
'
  Dim rpt As Access.Report
  Dim ctl As Access.control
'
  strRecordSource = "MyTableName"
  strRpt = "rptTmp"
'
  Set rpt = Application.CreateReport
'
  rpt.visible = False
'
' define report properties, unit is in twips.
'
  rpt.RecordSource = strRecordSource
  rpt.caption = "Special Report"
'
  rpt.DefaultView = acPreview
  rpt.Width = 9870
'
  rpt.visible = True
'
' save it with a name:
'
  DoCmd.Save acDefault, strRpt
'
' create a textbox for each field:
'
  strFld = "FieldName1"
  lLeft = 100
  lTop = 50
  lWidth = 2000
  lHeight = 250
'
  Set ctl = Application.CreateReportControl(strRpt, acTextBox, _
    acDetail, , strFld, lLeft, lTop, lWidth, lHeight)
  ctl.Name = strFld
  ctl.Fontsize = 8
'
' Create other controls...
'...
'
  DoCmd.Close acReport, strRpt, acSaveYes
'
' close ADO objects:
'
  Set ctl = Nothing
  Set rpt = Nothing
'
  rptCreateTmpReportSimple = strRpt
'
End Function

For your question:

I. You cannot delete page header and footer, but you can shrink them to 0 height.

II. Copy rptTmp to rptTmp2:

DoCmd.CopyObject , "rptTmp2", acReport, "rptTmp"

Upvotes: 3

Related Questions