Click to See Complete Forum and Search --> : Updating database


Bezzie
September 29th, 2001, 08:12 AM
Please help! I am a beginner with VB and need to update a DAO/Access 97 table with the old table data. The problem is that the new table has extra fields that's not in the old table.

How can i check each field from the new table to see if the same field exist in the old table so that i can import the data if it exist or add a default value if the field does not exist.

Any help please, i'm desperate!!!

Wynand

Cakkie
September 30th, 2001, 04:16 PM
A recordset has a fields collection, contining field objects. This way, you can do the check.

Dim fldNew as Field
Dim fldOld as Field

on error resume next ' disable errorhandling
for Each fldNew In rstNew
set fldOld = rstOld.Fields(fldNew.Name)
If Err.Number <> 0 then
' Field doesn't exist in old recordset
else
' Field exist in old recordset
End If
next fldNew




Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook