G
Guest
I have a function that checks to see if a value exists somewhere in a table
The code that I'm using currently is below - basically I create a recordset which consists of a SELECT statement WHERE the value is true. If the record count of the recordset is zero, I know the value doesn't exist
What I'm wondering is if there's a better way to do this - a faster way. Say without using a recordset - some function that exists that I don't know about. My program will be doing this type of thing a lot, so even a marginal time savings would be beneficial to me.
Thanks in advance!
Gre
CURRENT CODE:
Public Function IsInTable(TestString As Variant) As Boolea
Dim rstRecordset As Recordse
IsInTable= Fals
Set rstRecordset = CurrentDb.OpenRecordset("select FIELDNAME from TABLE where FIELDNAME = " & Chr(34) & TestString & Chr(34)
If rstRecordset.RecordCount = 0 The
IsInTable= Fals
Els
IsInTable= Tru
End I
rstRecordset.Clos
Set rstRecordset = Nothin
End Function
The code that I'm using currently is below - basically I create a recordset which consists of a SELECT statement WHERE the value is true. If the record count of the recordset is zero, I know the value doesn't exist
What I'm wondering is if there's a better way to do this - a faster way. Say without using a recordset - some function that exists that I don't know about. My program will be doing this type of thing a lot, so even a marginal time savings would be beneficial to me.
Thanks in advance!
Gre
CURRENT CODE:
Public Function IsInTable(TestString As Variant) As Boolea
Dim rstRecordset As Recordse
IsInTable= Fals
Set rstRecordset = CurrentDb.OpenRecordset("select FIELDNAME from TABLE where FIELDNAME = " & Chr(34) & TestString & Chr(34)
If rstRecordset.RecordCount = 0 The
IsInTable= Fals
Els
IsInTable= Tru
End I
rstRecordset.Clos
Set rstRecordset = Nothin
End Function