Click to See Complete Forum and Search --> : How To Test the field Whether Is Exist Or not
alwsid
Jul 2nd, 2000, 11:29 PM
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...
Clunietp
Jul 3rd, 2000, 12:58 AM
do you mean you want to see if a field exists, or a value for a certain field?
alwsid
Jul 3rd, 2000, 11:59 PM
Hi Tom.
yes I want to see whether a fields is exist or not.
Clunietp
Jul 4th, 2000, 12:17 AM
No Problem
are you using ADO or DAO, and which database (Access, SQL Server, etc...?)
Tom
alwsid
Jul 4th, 2000, 07:22 AM
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.
Clunietp
Jul 4th, 2000, 11:48 AM
DAO
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
and now for ADO:
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
alwsid
Jul 5th, 2000, 07:21 AM
Wow...
Thanks a lot Tom...
Clunietp
Jul 5th, 2000, 11:44 PM
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.