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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repairing a DB from code

Status
Not open for further replies.

8441

Technical User
May 9, 2001
54
GB
I have a database which I need to have an option to compact it via a button and then code behind that. I have found some code in this forum which I believe would work which is below.

DBEngine.RepairDatabase "C:\craig\Incident Management System - DEVELOPMENT\SJA-IMS"

The code is run from a seperate DB so the SJA-IMS isn't open. When I run it I get the error:

Operation is not supported for this type of object

Can anybody help please.
Thanks

 
I think you need an .mdb file in your string; i.e. "SJA-IMS.mdb"

Uncle Jack
 
Unfortunately that doesn't appear to work either. The same message appears. The completed code is below.


Private Sub Command0_Click()
' Repair SJA-IMS db
DBEngine.RepairDatabase "C:\craig\Incident Management System - DEVELOPMENT\SJA-IMS.mdb"


End Sub


Craig
 
Beats me. Your code seems correct provided that complicated path is precisely correct. Perhaps it's gagging on the long folder name and reading it or a part of it as the target which would give you the error you're experiencing. Why don't you move it somewhere simple, like C:\, and test it there to see if that's the problem?

Uncle Jack
 
I have just tried moving it to a simple location but it didn't work.

Thanks Uncle Jack for trying. can anyone else help. Would it make a difference in the fact that I have the tables and forms split?

craig
 
No, it doesn't make any difference if you've split the DB.

Uncle Jack
 
Stab in the dark time. I seem to remeber that in one of the menus you can select some additional libraries you can use, is DAO one of them.

secondly (this may confuse things) I have a seperate procedure which compacts the DB from another button which works fine. Does this use DAO.

If the second paragraph doesn't use DAO but the repair function does, where do I enable the DAO library?

craig
 
I have just found in a VB forum that Compacting also repairs the DB in Acces 2K so it appears I don't need to worry about repairing it.

craig
 
As to the DAO reference;
Open any module, Click on Tools,References and select Microsoft DAO 3.51 Object Library - Close/Reopen Db and try again.

Below is what I use:
Public Function RepairDatabases()

Call Shell("C:\MsAccessPath\msaccess.exe \\DbPath\DbName.mdb /Repair")

End Function

RGB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top