Solved How to define a conditional string in VBA

AlliCarr

Member
Local time
Today, 21:38
Joined
Feb 19, 2024
Messages
57
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
 
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,

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

Back
Top Bottom