C
Chris
Hi,
I have a form that contains a list box (lstReports). This list displays all
the reports of which prefix is either “rpt†or “rpfâ€. If the report prefix is
“rptâ€, the report opens directly. If the report prefix is “rpfâ€, the report
will open via a parameter form (for dates bracketing).
This is the VBA code on the OnOpen event of the form:
Private Sub Form_Open(Cancel As Integer)
Dim objAO As AccessObject
Dim objCP As Object
Dim strValues As String
Set objCP = Application.CurrentProject
For Each objAO In objCP.AllReports
If left(objAO.Name, 3) = "rpt" Or left(objAO.Name, 3) = "rpf" Then
strValues = strValues & Mid(objAO.Name, 4) & ";" & left(objAO.Name,
3) & ";"
End If
Next objAO
LstReports.RowSourceType = "Value List"
LstReports.RowSource = strValues
End Sub
Underneath the list box, I have a Text box called: txtReportDesc. This
allows me to see a brief description of the report before opening it.
This is the function I have put in:
Function ReportDescription(ReportName As Variant) As String
On Error GoTo Err_ReportDescription
Dim db As Database
Dim con As Container
Dim doc As Document
Dim prp As Property
Set db = CurrentDb()
Set con = db.Containers("Reports")
Set doc = con.Documents(ReportName)
Set prp = doc.Properties("description")
ReportDescription = prp.Value
Exit_ReportDescription:
Exit Function
Err_ReportDescription:
If Err.Number = 3270 Then
ReportDescription = "There is no description for this Report"
Resume Exit_ReportDescription
Else
MsgBox Err.Description
Resume Exit_ReportDescription
End If
End Function
This is the code for the OnOpen event of the list box which enables the
description to be displayed:
Private Sub LstReports_Click()
Me!txtReportDesc = ReportDescription("rpt" & Me!LstReports)
Me!txtReportDesc = ReportDescription("rpf" & Me!LstReports)
End Sub
This works well, but every time I click on a report’s name in the list box,
I get “Item not found in this collectionâ€, I press “OK†and the report opens.
I would like to get rid of this message, and any help would be really
appreciated.
I have a form that contains a list box (lstReports). This list displays all
the reports of which prefix is either “rpt†or “rpfâ€. If the report prefix is
“rptâ€, the report opens directly. If the report prefix is “rpfâ€, the report
will open via a parameter form (for dates bracketing).
This is the VBA code on the OnOpen event of the form:
Private Sub Form_Open(Cancel As Integer)
Dim objAO As AccessObject
Dim objCP As Object
Dim strValues As String
Set objCP = Application.CurrentProject
For Each objAO In objCP.AllReports
If left(objAO.Name, 3) = "rpt" Or left(objAO.Name, 3) = "rpf" Then
strValues = strValues & Mid(objAO.Name, 4) & ";" & left(objAO.Name,
3) & ";"
End If
Next objAO
LstReports.RowSourceType = "Value List"
LstReports.RowSource = strValues
End Sub
Underneath the list box, I have a Text box called: txtReportDesc. This
allows me to see a brief description of the report before opening it.
This is the function I have put in:
Function ReportDescription(ReportName As Variant) As String
On Error GoTo Err_ReportDescription
Dim db As Database
Dim con As Container
Dim doc As Document
Dim prp As Property
Set db = CurrentDb()
Set con = db.Containers("Reports")
Set doc = con.Documents(ReportName)
Set prp = doc.Properties("description")
ReportDescription = prp.Value
Exit_ReportDescription:
Exit Function
Err_ReportDescription:
If Err.Number = 3270 Then
ReportDescription = "There is no description for this Report"
Resume Exit_ReportDescription
Else
MsgBox Err.Description
Resume Exit_ReportDescription
End If
End Function
This is the code for the OnOpen event of the list box which enables the
description to be displayed:
Private Sub LstReports_Click()
Me!txtReportDesc = ReportDescription("rpt" & Me!LstReports)
Me!txtReportDesc = ReportDescription("rpf" & Me!LstReports)
End Sub
This works well, but every time I click on a report’s name in the list box,
I get “Item not found in this collectionâ€, I press “OK†and the report opens.
I would like to get rid of this message, and any help would be really
appreciated.