test for existence of a field 
Author Message
 test for existence of a field

How does go about testing for the presence of a field in a table?

For example, if you operate on several versions of a table, some of which
have an autonumber field and some don't and you want a generic way to, if
the autonumber is there, to sort it by the autonumber and pick records based
on the autonumber.  But, if it isn't there, to sort and retrieve on some
other field or combination of fields?

Thanks for suggestions.



Sun, 19 Aug 2001 03:00:00 GMT  
 test for existence of a field
You can do it two ways:
1) "Clean" way:
Iterate the Fields collection of the tabledef object.

dim fldMyField as field
dim tdfMyTable as tabledef
dim db as database
dim bolSuc as boolean
set db=CurrentDb
set tdfMyTable=db ("MyTable")
bolSuc=False
For each fldMyField in tdfMyTable.Fields
    if fldMyField.Name="Autonumberfield" then
        bolSuc=True
        exit for
    endif
Next fldMyField
...

2) "Dirty" way:
Try to get the field, if you dont get error is there ...

dim tdfMyTable as tabledef
dim db as database
set db=CurrentDb
set tdfMyTable=db.Tabledefs ("MyTable")
on error goto Err_Not_Found
tdfMyTable("Autonumberfield").Name
'ok ...

...
Err_NotFound:
'some code here ...

Alberto Borbolla
Microsoft MVP
Tecnologia en Sistemas
MEXICO

(replace "X" to send mail)


t>...

Quote:
>How does go about testing for the presence of a field in a table?

>For example, if you operate on several versions of a table, some of which
>have an autonumber field and some don't and you want a generic way to, if
>the autonumber is there, to sort it by the autonumber and pick records
based
>on the autonumber.  But, if it isn't there, to sort and retrieve on some
>other field or combination of fields?

>Thanks for suggestions.



Sun, 19 Aug 2001 03:00:00 GMT  
 test for existence of a field

Quote:

>You can do it two ways:
>1) "Clean" way:
>Iterate the Fields collection of the tabledef object.

>dim fldMyField as field
>dim tdfMyTable as tabledef
>dim db as database
>dim bolSuc as boolean
>set db=CurrentDb
>set tdfMyTable=db ("MyTable")
>bolSuc=False
>For each fldMyField in tdfMyTable.Fields
>    if fldMyField.Name="Autonumberfield" then
>        bolSuc=True
>        exit for
>    endif
>Next fldMyField
>...

>2) "Dirty" way:
>Try to get the field, if you dont get error is there ...

>dim tdfMyTable as tabledef
>dim db as database
>set db=CurrentDb
>set tdfMyTable=db.Tabledefs ("MyTable")
>on error goto Err_Not_Found
>tdfMyTable("Autonumberfield").Name
>'ok ...

>...
>Err_NotFound:
>'some code here ...

>Alberto Borbolla
>Microsoft MVP
>Tecnologia en Sistemas
>MEXICO

>(replace "X" to send mail)



e
>t>...
>>How does go about testing for the presence of a field in a table?

>>For example, if you operate on several versions of a table, some of which
>>have an autonumber field and some don't and you want a generic way to, if
>>the autonumber is there, to sort it by the autonumber and pick records
>based
>>on the autonumber.  But, if it isn't there, to sort and retrieve on some
>>other field or combination of fields?

>>Thanks for suggestions.



Mon, 20 Aug 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST

2. Testing for existence of a query

3. Testing for Existence of Table

4. Testing for a record already in existence

5. Test for table existence

6. Test for the existence of a table

7. Testing for a queries existence

8. Testing for table existence

9. Testing for table existence & listing available tables

10. Testing for file existence

11. Test for Contact EMail1Address existence

12. test existence of style

 

 
Powered by phpBB® Forum Software