Kamis, 05 April 2012

Re: Bls: [belajar-access] VBA Repair and Compact database

 

Dear Mas Andi,

Sekedar memperkaya pengetahuan dari yg sudah disampaikan Mas Syarief, kita bisa manfaatkan MSACCESS.EXE untuk melakukan compact. Dahulu masih zamannya file MDB di kawinkan dengan MDW. Ini saya copy paste kode yg dahulu saya gunakan.

Public Function Compact_MDB(My_MDB_File As String)
'Copyright © 2005, by Sofyan Efendi, all rights reserved.
On Error GoTo PesanError

Dim ms_access As String, mdw_file As String
Dim strPath As String, strPath2 As String

If Right(My_MDB_File, 4) <> ".mdb" Then
MsgBox "Yang hendak Anda compact bukan MDB file.",vbInformation ,"Not MDB file"
Exit Function
End If

'Tentukan lokasi MsAccess.Exe di PC Anda:
ms_access = """C:\Program Files\Microsoft Office XP\Office10\MSACCESS.EXE"" "

'Tentukan lokasi System.Mdw untuk file MDB Anda:
mdw_file = """C:\Program Files\Microsoft Office XP\Office10\System.mdw"" "
strPath = ms_access & My_MDB_File & " /WRKGRP " & mdw_file & "/compact "
Call Shell(strPath, vbHide)

KeluarProgram:
Exit Function

PesanError:
MsgBox "Error " & Err.Number & vbCrLf _
& Err.Description, vbCritical + vbOKOnly, App.Title
Resume KeluarProgram

End Function

O…ya, nama file dan folder diatas hanya contoh, Anda harus menyesuaikan dengan nama file dan folder di PC nya. Bila menggunakan Access 2007, toinggal dimodif sedikit kodenya.

Bagaimana seandainya file MDB Anda dipassword atau menggunakan level security menggunakan MDW ? Cukup modifikasi pada baris sbb:

strPath = ms_access & My_MDB_File & " /WRKGRP " & mdw_file & "/compact "

Menjadi:

strPath = ms_access & My_MDB_File & " /WRKGRP " & mdw_file & " /user "UserNameAnda" /pwd "PasswordAnda" /compact "

Wassalaamu'alaikum Warahmatullahi Wabarakatuh,
Sofyan Efendi.
http://imopi.wordpress.com/

--- In belajar-access@yahoogroups.com, Nyong Arif <nyong_arif@...> wrote:
>
> Dear Ali - Mungkin ini bisa membantu
>
> Letakkan Code ini di Module
>
>
> Public Sub CompactRepairAccessDB(ByVal sDBFILE As String, _
>             Optional sPASSWORD As String = "")
>
> Dim sDBPATH As String, sDBNAME As String, sDB As String, sDBtmp As String
> sDBNAME = sDBFILE 'extrapulate the file name
> Do While InStr(1, sDBNAME, "\") <> 0
>         sDBNAME = right(sDBNAME, Len(sDBNAME) - InStr(1, sDBNAME, "\"))
> Loop
> 'get the path name only
> sDBPATH = left(sDBFILE, Len(sDBFILE) - Len(sDBNAME))
>
> sDB = sDBPATH & sDBNAME
> sDBtmp = sDBPATH & "tmp" & sDBNAME
>
> 'Call the statement to execute compact and repair...
> If sPASSWORD <> "" Then
>         Call DBEngine.CompactDatabase(sDB, sDBtmp, dbLangGeneral, , ";pwd=" & sPASSWORD)
> Else
>         Call DBEngine.CompactDatabase(sDB, sDBtmp)
> End If
> 'wait for the app to finish
>         DoEvents
> 'remove the uncompressed original
>         Kill sDB
> 'rename the compressed file to the original to restore for other functions
>         Name sDBtmp As sDB
>
> End Sub
>
>  
> Cara Memanggil Procedurenya
>
>
> Private Sub BUT_COMPAC_Click()
>
> Call CompactRepairAccessDB("C:\Coba.mdb", "Password")
>
> End Sub
>
>
> Terima Kasih
>
> Salam,
> Syarief Nyong
>
>
>
> ________________________________
> Dari: Andi Ali <aliandi05@...>
> Kepada: "belajar-access@yahoogroups.com" <belajar-access@yahoogroups.com>
> Dikirim: Kamis, 5 April 2012 20:02
> Judul: [belajar-access] VBA Repair and Compact database
>
>
>  
> Mohon bantuannya,,, Source Code untuk meng-Repair dan Compact database gimana ya....
>
> mohon maaf kalo pertanyaan ini sudah pernah di tanyakan...
>
> makasi banyak.... 
>

__._,_.___
Recent Activity:
SPAM IS PROHIBITED
.

__,_._,___

Tidak ada komentar:

Posting Komentar