Change table structure with a split database.

I have been given the task of updating a distributed Access solution.  There is a need to add new fields to the database which has been split.

As I can not seem to use SQL to do this what can I do to make changes?
Who is Participating?
moduloConnect With a Mentor Commented:
Closed, 250 points refunded.

Community Support Moderator
Experts Exchange
Can you not go to the database in question then modify the table structure itself?

within the database window, click on Tables, then open up the table in design view

regarding the front-end, I assume they are linked tables, you can always delete and relink them either manually or by VBA code

If you require VBA code to do the relinking, I can certainly provide you with some
You should use SQL!!! To create a new table use CREATE TABLE sentence. To add fields to an existing table use ALTER TABLE sentence (look Jet SQL help for details).

And this way you can create a connection to a distant DB:

Dim db As DAO.Database
Set db = Workspaces(0).OpenDatabase("\\Tyan\Common\Velin\CompCom\CompComS_be.mdb", , False)
db.execute "Your sql sentence which adds new fields to the table"

But to change a table you must enter the DB monopolly.
Regards, Goliak.
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Matt-the-HATAuthor Commented:
rockiroads: unfortunatly I do not have access to the backend

But you have a point about useing VBA to relink after the update... I shall double the points on offer to cover the inclusion of such code.

goliak: your answer worked like a dream!   an easy 125 points will be heading your way soon.
I used this code to change the links on a frontend database that has table links to the backend

'Pass in path of DB, password if any, TRUE to create or FALSE to delete (note you got to delete existing before recreating)

Public Function Install_RefreshLinks(ByVal sDB As String, ByVal sPassword As String, ByVal bCreateLinks As Boolean) As Boolean
    Dim dbData As Database
    Dim tdData As TableDef
    Dim sTmp As String
    Dim i As Integer
    Dim bLoop As Boolean
    Dim iAbortLoop As Integer
    Dim bDone As Boolean
    Dim iCnt As Integer
    On Error GoTo ins_err
    Install_RefreshLinks = False
'Using refreshlink keeps failing with installable isam error,
'To avoid this on other client machines, Im cheating by deleting first

    iAbortLoop = 0
    If bCreateLinks = False Then
        Set dbData = CurrentDb
        bLoop = True
        iCnt = 0
        While bLoop = True
            bDone = False
            For Each tdData In dbData.TableDefs
                If tdData.Attributes = dbAttachedTable Then
                    If tdData.Name <> "RPT_Temp" Then
                        'Sleep (1000)
                        dbData.TableDefs.Delete tdData.Name
                        iCnt = iCnt + 1
                    End If
                    bDone = True
                End If
            Next tdData
            iAbortLoop = iAbortLoop + 1
            If bDone = False Or iAbortLoop = 500 Then
                bLoop = False
                MsgBox iCnt & " linked tables were removed.", vbInformation, APP_TITLE
            End If
        'Now recreate links
        'If Err.Number = 0 Then bCreateLinks = True
    End If
    If bCreateLinks = True Then
        iCnt = 0
        If sPassword <> "" Then
            Set dbData = DBEngine.Workspaces(0).openDatabase(sDB, False, False, ";PWD=" & sPassword)
            Set dbData = DBEngine.Workspaces(0).openDatabase(sDB)
        End If
        For Each tdData In dbData.TableDefs
            If tdData.Attributes = 0 Then
                If tdData.Name <> "RPT_Temp" And tdData.Name <> "MainMenu" Then
                    'Cater for temp tables used by Dev but not for release
                    If Left$(tdData.Name, 3) <> "xx_" Then
                        DoCmd.TransferDatabase acLink, "Microsoft Access", sDB, acTable, tdData.Name, tdData.Name, False
                        iCnt = iCnt + 1
                    End If
                End If
            End If
        MsgBox iCnt & " linked tables were created.", vbInformation, APP_TITLE
    End If

    Install_RefreshLinks = True
    GoTo ins_ok
    MsgBox "Error " & Err.Number & " trapped. " & vbCrLf & Err.Description, vbCritical, APP_TITLE

    Set dbData = Nothing
End Function
Matt-the-HATAuthor Commented:
in the end I found this did the job

Public Sub something()
    Dim db As DAO.Database
    Set db = Workspaces(0).OpenDatabase("C:\sb-Data\sb\sb_be.mdb", , False)
    db.Execute "ALTER TABLE [XS_FE] drop COLUMN FE_MarkUp SINGLE"
End Sub
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.