Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 26th, 2006, 07:23 AM
martin_g martin_g is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2006
Location: Edinburgh
Posts: 12 martin_g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 5 m 13 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old June 2nd, 2006, 06:32 AM
martin_g martin_g is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2006
Location: Edinburgh
Posts: 12 martin_g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 5 m 13 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Check if a field exists in a table (using VBA)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT