Solved How to define a conditional string in VBA (1 Viewer)

AlliCarr

New member
Local time
Today, 18:27
Joined
Feb 19, 2024
Messages
26
Hi,

I have the following code in the form load event of my reporting form:

Code:
Dim NewValList As String
NewValList = ""

Dim obj As AccessObject
For Each obj In CurrentProject.AllReports
NewValList = NewValList + Chr(34) + obj.Name + Chr(34) + ";"
Next obj

Me!ReportCombo.RowSourceType = "Value List"
Me!ReportCombo.RowSource = NewValList
Me!ReportCombo.value = Me!ReportCombo.ItemData(0)

This uses all the report names to create a value list so that the user can select which report they want to use. However, I also have sub reports which I don't want users to access. Is there any way I can exclude the sub reports from the NewValList string? All sub reports are named with "Sub" at the end.

Hope you can help.
Thanks
Allison
 

cheekybuddha

AWF VIP
Local time
Today, 18:27
Joined
Jul 21, 2014
Messages
2,321
Hi,

Just test before adding the report name if required:
Code:
' ...
For Each obj In CurrentProject.AllReports
  If Left(obj.Name, 3) <> "sub" Then
    NewValList = NewValList + Chr(34) + obj.Name + Chr(34) + ";"
  End If
Next obj
' ...
 

AlliCarr

New member
Local time
Today, 18:27
Joined
Feb 19, 2024
Messages
26
Hi,

Just test before adding the report name if required:
Code:
' ...
For Each obj In CurrentProject.AllReports
  If Left(obj.Name, 3) <> "sub" Then
    NewValList = NewValList + Chr(34) + obj.Name + Chr(34) + ";"
  End If
Next obj
' ...
Hi David,

That's great! I changed Left to Right as the 'Sub' was at the end and it worked a treat!

Many thanks :)
Allison
 

Users who are viewing this thread

Top Bottom