|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Check if a field exists in a table (using VBA)
Hi all,
I am working on a bit of VBA code for MS Access and need to check if a certain field exists in a table. My VBA skills are a bit rusty and google is no help at all. Any help would be much appreciated. Martin |
|
#2
|
|||
|
|||
|
I have found my own solution to this, and I thought I would post it in case anybody has the same problem.
I created a function to aid reusability: Code:
' test if fieldName field exists in tableName table
Function FieldExists(ByVal fieldName As String, ByVal tableName As String) As Boolean
Dim db As Database
Dim tbl As TableDef
Dim fld As Field
Dim strName As String
Set db = CurrentDb
Set tbl = db.TableDefs(tableName)
For Each fld In tbl.Fields
If fld.Name = fieldName Then
FieldExists = True
Exit For
End If
Next
' If FieldExists Then
' MsgBox "Field Name " + fieldName + " Exists in " + tableName
' Else
' MsgBox "Field Name Does Not Exist"
' End If
End Function
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Check if a field exists in a table (using VBA) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|