[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

copying an access table

Posted on 2001-07-30
3
Medium Priority
?
209 Views
Last Modified: 2010-05-19
i have a table called "Table1"

i want to make a copy of this table called "Table2"

then remove "Table1"

and rename "Table2" to "Table1"


0
Comment
Question by:Joshyy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Expert Comment

by:VK
ID: 6333737
Function CloneTDef(RefTDef As TableDef) As TableDef
    On Local Error GoTo Fehler
    '____________________________________________

    Dim NewTDef As TableDef
   
    Dim RefField As Field
    Dim NewField As Field
   
    Dim RefInd As Index
    Dim NewInd As Index
   
    Dim RefProp As Property
   
    '____________________________________________
    Set NewTDef = New TableDef
   
    '____________________________________________PROPERTIES
    For Each RefProp In RefTDef.Properties
        NewTDef.Properties(RefProp.Name).Type = RefProp.Type
        NewTDef.Properties(RefProp.Name).Value = RefProp.Value
        DoEvents
    Next
    NewTDef.Properties.Refresh
   
    '____________________________________________FIELDS
    For Each RefField In RefTDef.Fields
        Set NewField = NewTDef.CreateField
        For Each RefProp In RefField.Properties
            NewField.Properties(RefProp.Name).Type = RefProp.Type
            NewField.Properties(RefProp.Name).Value = RefProp.Value
            DoEvents
        Next
        NewTDef.Fields.Append NewField
    Next
    NewTDef.Fields.Refresh
   
    '____________________________________________INDEXES
   
    For Each RefInd In RefTDef.Indexes
        Set NewInd = NewTDef.CreateIndex

        For Each RefProp In RefInd.Properties
            NewInd.Properties(RefProp.Name).Type = RefProp.Type
            NewInd.Properties(RefProp.Name).Value = RefProp.Value
            DoEvents
        Next
       
        For Each RefField In RefInd.Fields
            Set NewField = NewInd.CreateField
            For Each RefProp In RefField.Properties
                NewField.Properties(RefProp.Name).Type = RefProp.Type
                NewField.Properties(RefProp.Name).Value = RefProp.Value
                DoEvents
            Next
            NewInd.Fields.Append NewField
        Next
        NewTDef.Indexes.Append NewInd
    Next
   
    NewTDef.Indexes.Refresh
   
    '____________________________________________
           
    Set CloneTDef = NewTDef
   
   
    Exit Function
Fehler:
    Select Case Err
        Case 3001, 3219, 3251, 3267, 3270, 3420
            Resume Next
        Case Else
            MsgBox Error
            Exit Function
    End Select
End Function


Sub ReplaceTable(NewTDef As TableDef, db As Database)
    On Local Error GoTo Fehler
    '____________________________________________
    If Not GetTableDef(db, NewTDef.Name) Is Nothing Then
        db.TableDefs.Delete (NewTDef.Name)
        db.TableDefs.Refresh
    End If
    db.TableDefs.Append NewTDef
    db.TableDefs.Refresh
    '____________________________________________
    Exit Sub
Fehler:
    Select Case Err
        Case Else
            MsgBox Error
            Exit Sub
    End Select
End Sub

Call ReplaceTable(CloneTDef(TDef), db)
0
 
LVL 6

Expert Comment

by:VK
ID: 6333739
sorry, a function is missing:

Public Function GetTableDef(db As Database, tabelle As String) As TableDef
    On Local Error GoTo Fehler
    '------------------------------------------------------------------------------------------
    Dim TDef As TableDef
    Set GetTableDef = Nothing
   
    For Each TDef In db.TableDefs
        If TDef.Name = tabelle Then
            Set GetTableDef = TDef
            Exit For
        End If
    Next
   
    '------------------------------------------------------------------------------------------
    Exit Function
Fehler:
    Select Case Err
        Case Else
            MsgBox Error
    End Select
End Function
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 6333750
1) Select Table1.* Into Table2 From Table1
2) Drop Table Table1
3) Various ways
i) Using access automation (DoCmd Rename)
ii) Using DAO (tabledefs collection)
iii) Using ADOX (Tables collection)

I can give you an example for any of the three.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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