Permission Error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Trying to add a field to a table using DAO. I was experimenting with a
single insert and I starting getting an error that I did not have permission
to update the database. I do have the permissions set correctly...I've owned
and updated these databases a number of times, but this is the first time
I've tried to do it through DAO. Simple code...any ideas?

Dim mydb As Database
Dim myname As String
Dim mytbl As TableDef

myname = "C:\dbsti\moblesti_be.mdb"
Set mydb = OpenDatabase(myname)
Set mytbl = mydb("Customers")

With mytbl
.Fields.Append .CreateField("RelatedAccounts", dbText, 30)

End With
 
Code should be:

Dim myWorkspace as DAO.Workspace
Dim mydb As DAO.Database
Dim mytbl As DAO.TableDef
Dim myname As String

myname = "C:\dbsti\moblesti_be.mdb"
Set myWorkspace = DBEngine.Workspaces(0)
Set mydb = myWorkspace.OpenDatabase(myname)
Set mytbl = mydb("Customers")
With mytbl
.Fields.Append .CreateField("RelatedAccounts", dbText, 30)
End With

This assumes you've running the code in a secured access database using the
same mdw file and user which has permissions to edit the db myname. Let me
know if you have any further probs.

Regards


Ian
 
Back
Top