Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    6

    Unanswered: Read the report caption field

    Help!

    All I want to do is drop the "proper names" for my reports into a combo box. I've tried reading the Report Description field, nothing. I'm trying now to read from the Reports() caption field and am stumped

    Private Sub cmdLoadList_Click()

    Dim iLoad As AccessObject
    Dim stDocName As String

    For Each iLoad In CurrentProject.AllReports
    DoCmd.OpenReport stDocName, acPreview, "", "", acWindowHidden
    ReportTitle.AddItem Item:=iLoad.Name & "," & Reports(iLoad.Name).Caption, Index:=jLoad
    DoCmd.Close acReport, stDocName
    jLoad = jLoad + 1
    Next iLoad

    End Sub

    Why is this not working, also it crashes in the Form_load event?

    Help!

  2. #2
    Join Date
    Mar 2004
    Location
    Brighton, UK
    Posts
    25

    Re: Read the report caption field

    Sorry I have no idea why that's not working but this is the way I'd do it:

    Dim rpt As Object
    Dim strSource As String

    DoCmd.Echo False
    For Each rpt In CurrentProject.AllReports
    DoCmd.OpenReport rpt.Name, acViewDesign
    strSource = strSource & Reports(rpt.Name).Caption & ";"
    '[for some reason rpt.caption gave an error]
    DoCmd.Close acReport, rpt.Name
    Next
    DoCmd.Echo True

    You could then assign strSource to the record source for the combo (with the Row Source Type set to Value List)

  3. #3
    Join Date
    Mar 2004
    Posts
    6

    Read caption worked great!

    Thank you, andysiant,

    The code worked great! I've attached the additional piece below.

    Long live encapsulation!

    Private Sub Form_Open(Cancel As Integer)
    DoCmd.Maximize
    Dim rpt As Object
    Dim strSource As String

    DoCmd.Echo False
    For Each rpt In CurrentProject.AllReports
    DoCmd.OpenReport rpt.Name, acViewDesign, "", "", acHidden
    strSource = strSource & rpt.Name & "," & Reports(rpt.Name).Caption & ";"
    '[for some reason rpt.caption gave an error]
    DoCmd.Close acReport, rpt.Name
    Next
    DoCmd.Echo True

    ReportTitle.ColumnCount = 2
    ReportTitle.ColumnWidths = "0 in;4 in"
    ReportTitle.BoundColumn = 1
    ReportTitle.RowSourceType = "Value List"
    ReportTitle.RowSource = strSource

    End Sub

  4. #4
    Join Date
    Mar 2004
    Location
    Brighton, UK
    Posts
    25

    Re: Read caption worked great!

    Glad it was of help. I've hardly seen CurrentProject and its methods etc before so it's good to have had a look at it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •