Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

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?
0
Matt-the-HAT
Asked:
Matt-the-HAT
1 Solution
 
rockiroadsCommented:
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
0
 
goliakCommented:
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.
0
 
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.
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
rockiroadsCommented:
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

    Err.clear
    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
        Wend
        '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)
        Else
            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
        Next
   
        MsgBox iCnt & " linked tables were created.", vbInformation, APP_TITLE
    End If

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

ins_ok:
    Set dbData = Nothing
End Function
0
 
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
0
 
moduloCommented:
Closed, 250 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now