2 Replies - 2517 Views - Last Post: 16 October 2007 - 08:01 AM Rate Topic: -----

#1 rightwest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-October 07

Compacting an access 2000 database

Posted 12 October 2007 - 01:07 AM

Hi,

I need some help with the code to compact a database
I am using VB6 and an access 2000 database i was wondering if anybody knew the code to compact it, all i have been able to find is how to compact it when using an access 95 database.

In particularly i am having trouble with this code

	'Close the database and make a backup copy
	gcnFmmc.Close
	FileCopy "Fmmc.mdb", "Fmmc.mdk"
	
	'Repair and compact to a temporary database
	lblMessage.Caption = "Compacting..."
	DBEngine.CompactDatabase "Fmmc.mdb", "Temp.mdb"	'This is the line of code i get an error on
	
	'Erase the temporary database
	Kill "Fmmc.mdb"
	Name "Temp.mdb" As "Fmmc.mdb"




thanks,
rightwest

Is This A Good Question/Topic? 0
  • +

Replies To: Compacting an access 2000 database

#2 MBraybrook  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 37
  • Joined: 14-August 06

Re: Compacting an access 2000 database

Posted 15 October 2007 - 03:38 AM

Try this:

http://www.mvps.org/...ral/gen0041.htm

Regards
M
Was This Post Helpful? 0
  • +
  • -

#3 AuGuS666  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 15-October 07

Re: Compacting an access 2000 database

Posted 16 October 2007 - 08:01 AM

:blink:

View PostMBraybrook, on 15 Oct, 2007 - 03:38 AM, said:



Did you ever try it???
Sorry but that's not a godf answer pal.... :v:

If you want to compact an M Access 2000 or better try this:

Private Sub Form_Load()
	'FIRST YOU NEED TO CREATE A REFERENCE TO: Microsoft Jet and Replication Objects 2.6 Library (or better)
	'NEW OBJECT TO COMPACT DB
	Dim jet As New JRO.JetEngine
	Dim sDBSource As String
		'DATABASE NAME SOURCE TARGET TO COMPACT
		sDBSource = "BigDB.mdb"
	Dim sDBTmp As String
		'TEMP NAME OF THE NEW COMPACT DATABASE
		sDBTmp = "DBT_" & Format$(Minute(Now), "00") & Format$(Second(Now), "00") & ".mdb"
		
		'MAIN METOD TO COMPACT THE DATABASE
		jet.CompactDatabase "Data Source=" & App.Path & "\" & sDBSource & ";" & _
							"Jet OLEDB:Database Password=", _
							"Data Source=" & App.Path & "\" & sDBTmp & ";" & _
							"Jet OLEDB:Database Password="
							
	  'DELETE SOURCE DATABASE
	  'Kill App.Path & "\" & sDBSource
	   
	  'RENAME NEW COMPACT DB WITH THE SOURCE DB NAME
	   Name App.Path & "\" & sDBTmp As App.Path & "\NewSmall" & sDBSource
	   
	  'NO LONGER NEED OF THE OBJECT
	   Set jet = Nothing
End Sub



Try with your own DB bevcouse the one in my example its empty but it makes the compact..

Easy right???

Attached File(s)


This post has been edited by AuGuS666: 16 October 2007 - 08:03 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1