Two Questions:

gblack

Registered User.
Local time
Today, 23:52
Joined
Sep 18, 2002
Messages
632
OK I know this must be silly easy to do...but how do you change the name of a table with code? If someone could give me a quick snippet of code on this, I would be thankfull.

Also, Is there any way to do an import into the same table over and over again, but have Access NOT append the new imported data? Meaning overwrite what is in there already? I am using some variables here in my code (ImportType, TableName etc...), but is there something I can add to make the import overwrite the old data?

DoCmd.TransferText acImportFixed, ImportType, TableName, Path, False, ""

Thanks for your help in advance:)
Gary
 
1) have a read on:
DAO - database.tabledefs
ADOX - schemas (search online)
2) delete query (delete * from tablename) to empty the table then import all
or update query from an imported table which does the above.
or code to import

Vince
 
hmm

1) I have tried to find stuff on the web about renaming tables. Didn't. But no matter...I a found a way around it

2) This was more what I was looking for:
DoCmd.DeleteObject acTable, "Table Name"
 
I'd make a Class for dealing with tables and include some functions like this:

Code:
Public Function RenameTable(ByVal strTable As String, ByVal NewName As String) As Boolean
    On Error GoTo Err_RenameTable
    Dim tdf As DAO.TableDef
    CurrentDb.TableDefs(strTable).Name = NewName
    RenameTable = True
    Exit Function
Err_RenameTable:
    RenameTable = False
End Function

Public Function Exists(ByVal strTable As String) As Boolean
    On Error GoTo Err_Exists
    Dim strTemp As String
    Dim tdf As DAO.TableDef
    strTemp = CurrentDb.TableDefs(strTable).Name
    Exists = True
    Exit Function
Err_Exists:
    Exists = False
End Function

Private Function DeleteTable() As Boolean
    On Error GoTo Err_DeleteTable
    Dim tdf As DAO.TableDef
    CurrentDb.TableDefs.Delete strTable
    DeleteTable = True
    Exit Function
Err_DeleteTable:
    DeleteTable = False
End Function
 

Users who are viewing this thread

Back
Top Bottom