Hello...
I want to know how to test the field whether is
exist or not and if the field is not exist, i want
to update my table with the code.
Hope somebody show me how...
Printable View
Hello...
I want to know how to test the field whether is
exist or not and if the field is not exist, i want
to update my table with the code.
Hope somebody show me how...
do you mean you want to see if a field exists, or a value for a certain field?
Hi Tom.
yes I want to see whether a fields is exist or not.
No Problem
are you using ADO or DAO, and which database (Access, SQL Server, etc...?)
Tom
Thanks Tom...
I'm using DAO.
But if you can give both example that's very nice to me.
May be one day I could change to ADO.
DAO
and now for ADO:Code:Dim db As Database
Dim rs As Recordset
Dim fld As Field
Dim blnFound As Boolean
blnFound = False
'open db/rs
Set db = DBEngine.OpenDatabase("Nwind.mdb")
Set rs = db.OpenRecordset("Customers")
'search thru fields
For Each fld In rs.Fields
If ucase(trim(fld.Name)) = "ADDRESS" Then
blnFound = True
Exit For
End If
Next fld
'do something if we found the field
If blnFound = True Then
MsgBox "Found It!"
End If
'cleanup
rs.Close
db.Close
Set fld = Nothing
Set rs = Nothing
Set db = Nothing
Code:Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim blnFound As Boolean
Dim lngCounter As Long
blnFound = False
'open db connection
Set cn = New Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Nwind.mdb"
'get rs
Set rs = cn.Execute("Select * from Customers", , adCmdText)
'loop thru fields
For lngCounter = 0 To rs.Fields.Count - 1
If UCase(Trim(rs.Fields(lngCounter).Name)) = "ADDRESS" Then
blnFound = True
Exit For
End If
Next lngCounter
'did we find it?
If blnFound = True Then
MsgBox "Found It"
End If
'cleanup
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
Wow...
Thanks a lot Tom...