Test if value is in any records of a field

J

JJJ

I want to make a public function using vba to test if a value is located
anywhere in a fields records. For example

FieldTest
A
B
C
D

If A is in FieldTest(and this checks all records)
Then something
Else something else
End if.

Thanks
 
B

Barry Gilbert

Public Sub ValExists(ByVal pValue As String)
If DCount("FieldTest", "MyTable", "[FieldTest] = '" & pValue & "'") Then
DoSomething
Else
DoSomethingElse
End If
End Sub

Barry
 
J

JJJ

Thanks for the fast response.
What if ComplianceIndexRange1 was a field in Query Tire? How would that work?
I am obviously new to access but I'm learning.

Public Function XStopCompliant(ByVal QFractComplianceIndex As String)
If DCount("ComplianceIndexRange1", "Tire", "[ComplianceIndexRange1] = '" &
QFractComplianceIndex & "'") Then
XStopCompliant = "No"
Else
XStopCompliant = "Yes"
End If
End Function

Barry Gilbert said:
Public Sub ValExists(ByVal pValue As String)
If DCount("FieldTest", "MyTable", "[FieldTest] = '" & pValue & "'") Then
DoSomething
Else
DoSomethingElse
End If
End Sub

Barry

JJJ said:
I want to make a public function using vba to test if a value is located
anywhere in a fields records. For example

FieldTest
A
B
C
D

If A is in FieldTest(and this checks all records)
Then something
Else something else
End if.

Thanks
 
B

Barry Gilbert

That should work as long as the query has no other criteria specified. The
DCount function (and others like DLookup, DSum, etc.) don't care if it's
looking at a table or a query.

Barry

JJJ said:
Thanks for the fast response.
What if ComplianceIndexRange1 was a field in Query Tire? How would that work?
I am obviously new to access but I'm learning.

Public Function XStopCompliant(ByVal QFractComplianceIndex As String)
If DCount("ComplianceIndexRange1", "Tire", "[ComplianceIndexRange1] = '" &
QFractComplianceIndex & "'") Then
XStopCompliant = "No"
Else
XStopCompliant = "Yes"
End If
End Function

Barry Gilbert said:
Public Sub ValExists(ByVal pValue As String)
If DCount("FieldTest", "MyTable", "[FieldTest] = '" & pValue & "'") Then
DoSomething
Else
DoSomethingElse
End If
End Sub

Barry

JJJ said:
I want to make a public function using vba to test if a value is located
anywhere in a fields records. For example

FieldTest
A
B
C
D

If A is in FieldTest(and this checks all records)
Then something
Else something else
End if.

Thanks
 
Top