Solved Open Form Where Condition Text Field (1 Viewer)

cktcPeterson

Member
Local time
Yesterday, 18:00
Joined
Mar 23, 2022
Messages
73
I have a student ID that looks like this

AB123456

I want to open a form based on a form

I have a combo box with a macro. I am stumpted on the where condition because it is a text field.

=" [Student ID] =" & [Student ID]
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:00
Joined
Oct 29, 2018
Messages
21,510
Try:
Code:
="[Student ID]='" & [Student ID] & "'"
 

cktcPeterson

Member
Local time
Yesterday, 18:00
Joined
Mar 23, 2022
Messages
73
Exactly what I was looking for.
Thanks
 

Josef P.

Well-known member
Local time
Today, 04:00
Joined
Feb 2, 2023
Messages
835
[something OT]

Since merging a filter string is an ongoing issue, I was about to give the tip to use BuildCriteria, as this will create a correct filter expression.

Example:
Code:
Dim FilterValue As String
Dim FilterString As String

FilterValue = "AB123456"
FilterString = BuildCriteria("[Student ID]", DataTypeEnum.dbText, FilterValue)
Debug.Print FilterString
This fits in principle, unless you include " in the string.
Code:
FilterValue = "abc""xyz" ' ... Value = abc"xyz
FilterString = BuildCriteria("[Student ID]", DataTypeEnum.dbText, FilterValue)
Debug.Print FilterString
=> [Student ID]="abc"xyz" 🧨
I use my own method, so I have too little practice with the built-in BuildCriteria. ;)
But I would have expected Access.BuildCriteria to at least double the ".

However, it can handle such an expression:
Code:
FilterValue = "abc or xyz"
FilterString = Access.BuildCriteria("[Student ID]", DataTypeEnum.dbText, FilterValue)
Debug.Print FilterString
=> [Student ID]="abc" Or [Student ID]="xyz"

What do you suspect is coming with this filter value:
Code:
FilterValue = "abc;xyz"
 
Last edited:

Users who are viewing this thread

Top Bottom