Solved

How to check if an Access column exists

Posted on 1998-06-17
1
129 Views
Last Modified: 2008-03-04
I need to find out how to check if an Access column exists.

If an Access column does not exist my VB app. must add it.
0
Comment
Question by:jfl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
cerik earned 20 total points
ID: 1463531
try this, just stick it in a sub or function

Dim ws As Workspace
Dim db As Database
Dim FieldX As Field
Dim Searchstr As String
Dim index As Integer
Dim tdef As TableDef
'connect up to database
Set ws = Workspaces(0)
Set db = ws.OpenDatabase("D:/mydb") 'or whereever yours is
'get a tabledef to work with
Set tdef = db.TableDefs!myTable
'set column search name
Searchstr = "unknown"
index = -1
'scan thru column(fields) for match
For Each FieldX In tdef.Fields
    If FieldX.Name = Searchstr Then index = FieldX.OrdinalPosition
Next
'if no ordinal position found then add
If index = -1 Then
    'check that you can update
    If tdef.Updatable Then
        tdef.Fields.Append tdef.CreateField(Searchstr, dbText, 50)
    'you can add as different fields and field size but both are optional
    End If
End If


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
using Access 8 92
How to debug this code 7 65
Set WorkSheet  not Working 9 62
VB6 Enviroment 3 35
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question