Just a follow up to this process, as I've been trying to do the same thing, but it appears that you cannot be in the database from which you wish to create the mde (the source database). I've successfully used code similar to the above, but have not been successful if running it from the source database.
My dilemma is that I have an application installed for a user that is remote - and rather than trying to talk them through creating the mde (accde) I wanted to do it for them in the new version of the front end.... but it doesn't work as described above.
If someone has a solution to this, I'd be very keen.
Thanks,
Don