Jumat, 06 April 2012

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

 

Dear Mas Andi,

Untuk Access 2003 dan versi sebelumnya:

Private Sub cmdTest_Click()
On Error GoTo Err_cmdTest_Click
'7 April 2012, Ba'da Subuh di BTR
'Kode dijamin jalan, pengalaman zaman dulu waktu pake acc 2003

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction

Exit_cmdTest_Click:
Exit Sub

Err_cmdTest_Click:
MsgBox Err.Description, vbExclamation, "Error in cmdTest_Click()"
Resume Exit_cmdTest_Click
End Sub

Untuk Access 2007:

Private Sub cmdTest_Click()
On Error GoTo Err_cmdTest_Click
'7 April 2012, Ba'da Subuh di BTR
'Nyari di google ngga ada, terpaksa buat sendiri, he..he..
'Tested by laptop serpisan tetangga, acc 2007..
'Hasil : Gagal, keluar pesen error di access

SendKeys "%{F}", True
SendKeys "F", True
SendKeys "M", True
SendKeys "C", True

Exit_cmdTest_Click:
Exit Sub

Err_cmdTest_Click:
MsgBox Err.Description, vbExclamation, "Error in cmdTest_Click()"
Resume Exit_cmdTest_Click
End Sub

Untuk Access 2010:

Private Sub cmdTest_Click()
On Error GoTo Err_cmdTest_Click
'7 April 2012, Ba'da Subuh di BTR
'sambil dengerin istri ngaji dikamar belakang...
'Test by PC core 2 duo, acc 2010, 100% qc passed :)
'all code work succesfully

SendKeys "%{F}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{ENTER}", True

Exit_cmdTest_Click:
Exit Sub

Err_cmdTest_Click:
MsgBox Err.Description, vbExclamation, "Error in cmdTest_Click()"
Resume Exit_cmdTest_Click
End Sub

Kesimpulan, Access selain 2007 berhasil, buat temen2 yg sudah dapat solusi, please, tolong banget dishare dimari. Trm ksh.

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

--- In belajar-access@yahoogroups.com, Andi Ali <aliandi05@...> wrote:
>
> makasi mas syarief dan mas sofyan.. sudah saya coba dan berhasil...
> namun yang saya harapkan adalah meng-Compac dan repair data pada file access yang terkait, bukan file access di luar aplikasi yang dijalankan...
> mohon penjelasannya....
>
>
> ________________________________
> From: Sofyan Efendi <sofyanefendi@...>
> To: belajar-access@yahoogroups.com
> Sent: Friday, April 6, 2012 6:06 AM
> Subject: 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