Solved

Change table structure with a split database.

Posted on 2004-03-29
8
251 Views
Last Modified: 2008-03-17
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
Comment
Question by:Matt-the-HAT
8 Comments
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
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
 
LVL 4

Expert Comment

by:goliak
Comment Utility
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
 
LVL 2

Author Comment

by:Matt-the-HAT
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
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
 
LVL 2

Author Comment

by:Matt-the-HAT
Comment Utility
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
 

Accepted Solution

by:
modulo earned 0 total points
Comment Utility
Closed, 250 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now