troubleshooting Question

Delete field from back end Access table using code

Avatar of emcullen
emcullen asked on
Microsoft Access
1 Comment1 Solution206 ViewsLast Modified:
I have an Access application with a backend database.  I am changing the application and I need to delete some fields from the backend database.  SInce the application has been deployed around the world, I don't know the name of the backend databases that are out there or what version they are running.  I want to run a routine when the application opens that checks the fields in specific tables on the backend database the user chooses to connect to (they can name them anything they want) and if a field exists, delete it.  The code I've tried is as follows but it does not work: ( I took most of it from a previous question I had asked about adding a field to the same remote back end database - that code works like a charm)

Dim vPath As String
Dim db As Database
Dim tbl As DAO.TableDef
Dim fld As DAO.Field

Dim i As Integer
Dim bFound As Boolean

'remove rm_Line_type from rm_type_id
Set tbl = db.TableDefs("rm_type_id")   ' table name

bFound = False
i = 0
For i = 0 To tbl.Fields.Count - 1
    If tbl.Fields(i).Name = "rm_line_type" Then   ' field name to delete
        bFound = True
        Exit For
    End If
Next i
If bFound = True Then
    tbl.Fields.Delete "rm_Line_type"
End If
db.Close
Set fld = Nothing
Set tbl = Nothing
Set db = Nothing
ASKER CERTIFIED SOLUTION
frankytee

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros