Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Function to check to see if a variable exists in a set?

Status
Not open for further replies.

ChrisOjeda

Programmer
Apr 16, 2003
45
US
Hi,

I was trying to locate a VBA Fuction to check to see if my variable exists in a set instead of writing a massive IF THEN?

Thanks... Chris
 
I'm not sure that I understand the question. Do you mean to check whether a field exists in a recordset??

If the above interpretation is correct, then the following code can be used:
[tt]
YourFieldName = "YourField"
YourFieldFound = False
For Each F In RS.Fields
If F.Name = YourFieldName Then
YourFieldFound = True
Exit For
End If
Next F
[/tt]
The above assumes that the recordset has already been successfully opened; Replace "YourField" above, as appropriate. Better still, turn the above code into a simple function, and pass the recordset and field name as parameters to the function.

I hope this answers the question; otherwise provide more info about what you're looking for.

Cheers,


Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top