Can anybody help me?
I am new to using code in my access database.
I am currently developing a front end back end database where the back end is a replica.
For security reasons I need to delete one of the tables from the front end using code because the relationships to other tables are stopping me from using a macro.
So far I have the following code where "company" is the table that I want to delete. When I run this code I get the error "An unexpected error (3452) occured: You can't make changes to the design of the database in this replica."
Here is the Code:
Private Sub Command24_Click()
'
' Deletes all relationships associated with a table.
'
' This is needed if you have a relationship on a linked table, and the
' source of the attachment has been moved/deleted. Without DAO, you wouldn't
' be able to delete the relationship in order to delete the table.
'
' You can also use this to delete relationships of non-linked tables.
'
Dim Db As DAO.Database, i As Integer
On Error GoTo DRErr
Set Db = CurrentDb
For i = Db.Relations.Count - 1 To 0 Step -1
If (Db.Relations(i).Table = "Company") Or (Db.Relations(i).ForeignTable = "Company") Then
Db.Relations.Delete Db.Relations(i).Name
End If
Next i
'
' Optional code to delete tabledef if it is a linked table
'
' If (db.TableDefs("Company").Attributes And dbAttachedTable) Then
' db.TableDefs.Delete "Company"
' Else
' MsgBox "Not a linked table."
' End If
DRExit:
Exit Sub
DRErr:
If Err.Number = 3265 Then
MsgBox "There is no table named " & "Company" & " in this database."
Else
MsgBox "An unexpected error (" & Err.Number & ") occurred: " & Err.Description
End If
Resume DRExit
End Sub
Thanks in advance
I am new to using code in my access database.
I am currently developing a front end back end database where the back end is a replica.
For security reasons I need to delete one of the tables from the front end using code because the relationships to other tables are stopping me from using a macro.
So far I have the following code where "company" is the table that I want to delete. When I run this code I get the error "An unexpected error (3452) occured: You can't make changes to the design of the database in this replica."
Here is the Code:
Private Sub Command24_Click()
'
' Deletes all relationships associated with a table.
'
' This is needed if you have a relationship on a linked table, and the
' source of the attachment has been moved/deleted. Without DAO, you wouldn't
' be able to delete the relationship in order to delete the table.
'
' You can also use this to delete relationships of non-linked tables.
'
Dim Db As DAO.Database, i As Integer
On Error GoTo DRErr
Set Db = CurrentDb
For i = Db.Relations.Count - 1 To 0 Step -1
If (Db.Relations(i).Table = "Company") Or (Db.Relations(i).ForeignTable = "Company") Then
Db.Relations.Delete Db.Relations(i).Name
End If
Next i
'
' Optional code to delete tabledef if it is a linked table
'
' If (db.TableDefs("Company").Attributes And dbAttachedTable) Then
' db.TableDefs.Delete "Company"
' Else
' MsgBox "Not a linked table."
' End If
DRExit:
Exit Sub
DRErr:
If Err.Number = 3265 Then
MsgBox "There is no table named " & "Company" & " in this database."
Else
MsgBox "An unexpected error (" & Err.Number & ") occurred: " & Err.Description
End If
Resume DRExit
End Sub
Thanks in advance