Vous êtes sur la page 1sur 4

Curso de Visual Basic Aplicado Harley Solano Sánchez

Compactar y Reparar una Base de Datos desde Visual Basic


1. Agregar un formulario en al Sistema con las siguientes propiedades

Nombre = Compacta
Caption = Compactando El Chele
BackColor = &H0000C0C0&
ControlBox = False
MDIChild = False
Height = 1345
Left = 4815
StartUpPosition = 0 – Manual
Top = 3480
Width = 6000

2. Agregar al proyecto la siguiente referencia Microsoft Jet and Replication


Objects 2.6 Library, haga clic en Proyecto y luego clic en Referencias..

3. Inserte en el formulario un botón de comando con las siguientes propiedades

Nombre = Iniciar
Caption = Compactar
Height = 255
Left =0
Top =0
Width = 1095

4. Inserte en el formulario un botón de comando con las siguientes propiedades

Nombre = Salir
Caption = Cerrar
Height = 255
Left = 4800
Top = 600
Width = 1095

5. Inserte en el formulario un botón de comando con las siguientes propiedades

Nombre = Animacion
Caption = “” (Vacia)
Style = 1 - Graphical
Height = 615
Left = 2040
Top = 120
Width = 855

harley.solano@gmail.com hasx1@hotmail.com
Curso de Visual Basic Aplicado Harley Solano Sánchez

6. Insertar un objeto Timer con las siguientes propiedades

Nombre = Animar
Enabled = True
Interval = 500

7. Escribir el siguiente código para el botón de comando llamado Salir

Objeto : Boton Salir

Evento : Click

Código :

Private Sub Salir_Click()


Compacta.Hide
End Sub

8. Escribir el siguiente código para el objeto Timer llamado Animar

Objeto : Timer Animar

Evento : Timer

Código :

Private Sub Animar_Timer()


Static mostrar As Integer
If mostrar Then
Animacion.Picture = LoadPicture("C:\El Chele\iconos\Kardex.ico")
Else
Animacion.Picture = LoadPicture("C:\El Chele\iconos\registrar.ico")
'Animacion.Picture = LoadPicture("C:\El Chele\iconos\producto2.ico")
End If
mostrar = Not mostrar
End Sub

harley.solano@gmail.com hasx1@hotmail.com
Curso de Visual Basic Aplicado Harley Solano Sánchez

9. Escribir el siguiente código para el botón de comando llamado Iniciar


Objeto : Boton Iniciar
Evento : Click
Código :
Private Sub Iniciar_Click()
Dim JR As New JRO.JetEngine
Dim DbOriginal As String, DbTemporal As String
On Error GoTo ErroCompactar
DbOriginal = App.Path & "\chele.mdb"
DbTemporal = App.Path & "\cheleTmp.mdb"
If Right$(App.Path, 1) = "\" Then
DbOriginal = App.Path & "chele.mdb"
DbTemporal = App.Path & "cheleTmp.mdb"
End If
If Dir$(DbTemporal) <> "" Then
Call Kill(DbTemporal)
End If
JR.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DbOriginal & ";", _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DbTemporal & ";Jet." & _
"OLEDB:Engine Type = 5;"
If Dir$(DbOriginal) <> "" Then
Call Kill(DbOriginal)
End If
JR.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DbTemporal & ";", _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & DbOriginal & ";Jet." & _
"OLEDB:Engine Type = 5;"
MsgBox "Base de Datos Compactada"
Beep
Beep
Exit Sub
ErroCompactar:
MsgBox "No se puede Compactar en estos momentos la Base de Datos " & DbOriginal + _
" Este proceso solamente se realiza al momento de cargar el Sistema", vbOKOnly +
vbInformation, "Error al Compactar"
WindowState = 2
MsgBox Err.Description
Err.Clear
End Sub

harley.solano@gmail.com hasx1@hotmail.com
Curso de Visual Basic Aplicado Harley Solano Sánchez

harley.solano@gmail.com hasx1@hotmail.com

Vous aimerez peut-être aussi