apollois
asked on
Determine if Field Exists in Recordset
How can I determine if a field is part of a recordset?
I don't want to loop through the Fields collection, or use ON ERROR.
Example:
rstMyTable.open "SELECT * FROM MyTable", objConn
If the field "Myfield" does not exist:
IsObject(rstMyTable.Fields ("Myfield" )) 'returns error 3265
IsNull(rstMyTable("Myfield ")) 'returns error 3265
Any ideas?
I don't want to loop through the Fields collection, or use ON ERROR.
Example:
rstMyTable.open "SELECT * FROM MyTable", objConn
If the field "Myfield" does not exist:
IsObject(rstMyTable.Fields
IsNull(rstMyTable("Myfield
Any ideas?
ASKER
shanesuebsahakarn,
>>>Why are you unable to loop through the collection or error trap ?
Constraints given to me.
>>>Also, under what circumstances do you need to test for the field's existence ?
I have a custom DLL which returns a recordset. It returns different fields depending on the criteria. I do not have access to the DLL or it's source code.
Best Regards,
>apollois<
>>>Why are you unable to loop through the collection or error trap ?
Constraints given to me.
>>>Also, under what circumstances do you need to test for the field's existence ?
I have a custom DLL which returns a recordset. It returns different fields depending on the criteria. I do not have access to the DLL or it's source code.
Best Regards,
>apollois<
Use:
ON ERROR RESUME NEXT
then assign isnull(rstMyTable.fields(" Myfield")) to a variable.
Check for an error 3265. If it is there, then the field does not exist. If the ERR=0, then the field exists.
ON ERROR RESUME NEXT
then assign isnull(rstMyTable.fields("
Check for an error 3265. If it is there, then the field does not exist. If the ERR=0, then the field exists.
Sorry, I missed the part about not using ON ERROR
ASKER
Moliere,
Please re-read my question:
I don't want to loop through the Fields collection, or use ON ERROR.
Best Regards,
>apollois<
Please re-read my question:
I don't want to loop through the Fields collection, or use ON ERROR.
Best Regards,
>apollois<
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I am not sure of your situation, but if you are trying to determine which of two nearly identical tables you are selecting from, save MyField, then you could possibly use a count of the fields to tell if it is there.
I don't see any reason NOT to loop through the fields collection. It takes almost no time, and is the only solution I can think of.
ASKER
I think you're right. The only options are check the Fields collection or use ON ERROR.
This is what I thought, but others were insisting there must be another way.
Thanks to all for confirming this. Shane was first, so he gets the points.
This is what I thought, but others were insisting there must be another way.
Thanks to all for confirming this. Shane was first, so he gets the points.
Also, under what circumstances do you need to test for the field's existence ?