Results 1 to 2 of 2
2003-08-22, 21:28 #1
- Join Date
- Apr 2003
- Thanked 0 Times in 0 Posts
Check for existing fields in a table. (Access2000)
I have an application which links tables from a user selected database to the application database. The user wanted two additional fields added to the table that has nearly a hundred existing databases.
Can I check within my application which structure (the table name is the same) is linked to the application. Is there a way to look for the presence or absence of these fields in an If..then statement?
(The table name is JobPos and the two additional fields to the newer table structure are MAppl and MIntv).
I do NOT want to redo ALL the existing table structures. If I know if these two fields are present or absent I can make the calculation based on the data available at the time the table was created.
I hope this makes sense. If you need more info please email me.
2003-08-22, 21:50 #2
- Join Date
- Mar 2002
- Thanked 28 Times in 28 Posts
Re: Check for existing fields in a table. (Access2000)
You can open an ADO or DAO recordset on the linked table, whichever you're most comfortable with. Then, test whether the additional fields exist. Let's assume that you have opened a recordset named rst on the linked table.
Dim strFieldName As String
Dim blnNewFieldExists As Boolean
' Avoid error message.
On Error Resume Next
' Try to retrieve field name, just to see if an error occurs
strFieldName = rst.Fields("MAppl").Name
' Was there an error?
blnNewFieldExists = (Err = 0)
' Close record set
Set rst = Nothing
' Restart normal error handling
On Error GoTo MyErrorHandler ' or 0 if you don't have error handling