Results 1 to 2 of 2

Thread: Excel VBA Macro - Drop Access (.mdb) Column

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    1

    Excel VBA Macro - Drop Access (.mdb) Column

    Hello all,

    I have a seriese of excel VBA tools which I have put together for a series of functions for other users within my company to use and need to add the following functionality to it

    Point to a directory of .mdb access files with various names
    Always with the same table name "TREES" I need to remove the first columbn a primary Key "MAPINFO_ID"

    The following is my attempt can someone tell me what more I need to know to get this functional, thank you for taking the time to read this post

    <code>

    Sub Drop_Mapinfo_ID_Test()
    Dim db As Database
    Dim T As TableDef
    Dim MyDir, MyMDB, MyN, MyM, MyListCell, MyMDBCell As String
    Dim n As String

    ' Dim db As DAO.Database
    Dim tdf As DAO.TableDef
    Dim fld As DAO.Field

    Columns("R:R").Select
    Selection.ClearContents

    Application.ScreenUpdating = False

    MyDir = Range("J3").Value
    MyMDB = Range("J4").Value

    'Set result cell count
    n = 4
    MyN = n

    MyListCell = "R" + MyN

    Range("J4").Select
    Do Until IsEmpty(ActiveCell)

    MyMDB = ActiveCell

    Set db = OpenDatabase(MyDir + "/" + MyMDB)
    'Set DB = OpenDatabase(GetFilename())
    For Each T In db.TableDefs
    T.Fields.Delete "MAPINFO_ID"
    Next

    ActiveCell.Offset(1, 0).Select

    Loop

    End Sub

    /<code>

  2. #2
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,528

    Re: Excel VBA Macro - Drop Access (.mdb) Column

    The following is my attempt can someone tell me what more I need to know to get this functional,
    what is happening now (or not)? do you need to close the database and save changes to the tabledef?
    if there are other tables in the database, that do not have that field, you should test the name of the table against the tabledef
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •