Permission Error

B

brian

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
 
I

IanOxon via AccessMonster.com

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top