Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime Error 3051

Status
Not open for further replies.

dalec

Programmer
Jul 8, 2000
191
US
I recently ran in to this error, didnt find much help. I did not change anything in my code to connect to the database differntly. But after some database work (access 2000 on a windows 2000 server), my program kept getting this error. I ended up creating a new blank database and importing the tables from the existing database and deleted the old database and renamed the new database to the original database name. Everything worked fine, and was back to normal.
 
Is there still a problem that you are needing help with?
 
No, I spent about 4 hours this morning on it and by just creating a new database and importing the tables from the old one, solved the error. I thought it might be helpful if I posted my solution, incase someone else was having trouble finding a solution for it.
Thanks for your response!
Dale
 
Cool beans. :) I wasn't sure if you were seeking the "why" for that problem or if (as was the case) you were letting others know the fix (kudos for that by the way - I hate when people post a problem, then just say "fixed it!" without saying how - not too helpful for others with the same problem searching the posts).
 
Hi,
I'm using:

set x=opendatabase(filename,,true)' read only

to open an Access db on a CD for read only purpuse and get the Error 3051 still.

Any Idea why ?

Thanks
Daniel
 
dgeva,

I've noticed that this problem seems to be with the sytem locking the file or marking it readonly. Of course in your case it is readonly because it's on a CD. The only thing I can think to suggest is that making sure your call to open the file is readonly and for sure not read/write. I have had access databases, open (even in read write mode) and only error when I tried a write operation (I might try changing your open statement to read/write just to see if it will open. When creating the data to the CD make sure it will open as normal before creating the CD to isolate that the problem isnt with the file itself. If I can offer more insite I will. Hope this give you some other things to try.

Dale
 
The same DB file when being moved from the CD to the hard disk works fine with the same code. On the other hand when double clicking the file on the CD it opens as read only DB after a warning. So I fail to understand the mechanism here.

Thanks

Dan
 
This is how I do mine:
In a module I declare;

Code:
Global DBName As String
Global Wk_area As Workspace
Global DBSFund As Database

Public Sub OpenDB()
Dim MyLine As Long
   On Error GoTo err_handler
   MyLine = 1
   DBName = App.Path & "\StudData.mdb"
   MyLine = 2
   ' odbc
   Set Wk_area = CreateWorkspace ("ODBCWorkspace", "admin", "", dbUseODBC)
   MyLine = 3
   Workspaces.Append Wk_area
   MyLine = 5
   Set DBSFund = DBEngine.OpenDatabase(DBName, False, False)
   Exit Sub
err_handler:
   MsgBox "The code failed at line " & Erl & " " & MyLine, vbCritical
   Exit Sub
End Sub

(then when ever I want to open the database to use I call)

OpenDB

(course I'm setting my database to read-write, but it would open the database regardless of readonly, because it won't error unless I try to do a write operation).

I have had in some cases code not run, but when I assign things to vars they work, one issue like that is crystal reports, often times I cant get a selection formula to work, but if I code the formula in a var, then pass it, it will work (I know it's strange, but sometimes you have to do things differntly than documented!)

Maybe this code snip it will help?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top