|
-
Jul 2nd, 2000, 11:29 PM
#1
Thread Starter
Lively Member
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...
-
Jul 3rd, 2000, 12:58 AM
#2
Guru
do you mean you want to see if a field exists, or a value for a certain field?
-
Jul 3rd, 2000, 11:59 PM
#3
Thread Starter
Lively Member
Hi Tom.
yes I want to see whether a fields is exist or not.
-
Jul 4th, 2000, 12:17 AM
#4
Guru
No Problem
are you using ADO or DAO, and which database (Access, SQL Server, etc...?)
Tom
-
Jul 4th, 2000, 07:22 AM
#5
Thread Starter
Lively Member
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.
-
Jul 4th, 2000, 11:48 AM
#6
Guru
DAO
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
and now for ADO:
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
-
Jul 5th, 2000, 07:21 AM
#7
Thread Starter
Lively Member
Wow...
Thanks a lot Tom...
-
Jul 5th, 2000, 11:44 PM
#8
Guru
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|