Hey all - long time no posting!
I am back improving my database, and have run into a little issue. Last year I stumbled on a great resource that taught me how to build forms which filter reports.
I am now working on a new one of these reports and filtering forms; one of the filters is based on people's names in my database. Here is the code used to build a string from items selected from a list box on that form:
And then the code that builds the filter string:
The issue is when I have multiple records with the same last name. If I select "Anderson, Ashley" and filter, it shows Ashley Anderson, but also Kevin Anderson, Scott Anderson, etc.
I have been trying to figure out a way around this. My most recent attempts have been to use the Primary Key - adding that to the report as a hidden field. The problem I'm having is that my VBA code to filter builds a string, and the PK value is an integer. And I want the user to be able to filter by multiple teachers at once, so the solution would need to hold multiple integers (PKs). I think using an array might be the key, but I can't figure it out. I'm totally unfamiliar with arrays and have been trying to teach myself how to properly implement them. If an array is the answer, I am not sure how to build that into my filtering string.
There are a few other ways I might be able to accomplish this as well - such as using both first and last name. All help is welcome!
I am back improving my database, and have run into a little issue. Last year I stumbled on a great resource that taught me how to build forms which filter reports.
I am now working on a new one of these reports and filtering forms; one of the filters is based on people's names in my database. Here is the code used to build a string from items selected from a list box on that form:
Code:
For Each varItem In Me.lstTeachers.ItemsSelected
strTeacherName = strTeacherName & ",'" & Me.lstTeachers.ItemData(varItem) & "'"
Next varItem
If Len(strTeacherName) = 0 Then
strTeacherName = "Like '*'"
Else
strTeacherName = Right(strTeacherName, Len(strTeacherName) - 1)
strTeacherName = "IN(" & strTeacherName & ")"
End If
Code:
strFilter = "[ProgramName] " & strProgName & " AND [ProgramType] " & strProgType & " AND [SchoolName] " & strSchool _
& " AND [LastName] " & strTeacherName
The issue is when I have multiple records with the same last name. If I select "Anderson, Ashley" and filter, it shows Ashley Anderson, but also Kevin Anderson, Scott Anderson, etc.
I have been trying to figure out a way around this. My most recent attempts have been to use the Primary Key - adding that to the report as a hidden field. The problem I'm having is that my VBA code to filter builds a string, and the PK value is an integer. And I want the user to be able to filter by multiple teachers at once, so the solution would need to hold multiple integers (PKs). I think using an array might be the key, but I can't figure it out. I'm totally unfamiliar with arrays and have been trying to teach myself how to properly implement them. If an array is the answer, I am not sure how to build that into my filtering string.
There are a few other ways I might be able to accomplish this as well - such as using both first and last name. All help is welcome!