Pasos Para Enlazar Access Con Visual Basic 6

12
PASOS PARA ENLAZAR ACCESS CON VISUAL BASIC 6.0 1.- Botón secundario sobre el cuadro de herramientas elegir componentes. 2.- En la ventana que aparece seleccionar “Microsoft ADO Data control 6.0 (OLEDB). Presionar Aceptar. 3.- En el cuadro de herramientas aparecera el icono siguiente colocarlo en el formulario. 4.- seleccionar el ADODC1 y modificar las siguientes propiedades: CONECCIONSTRING: PRESIONAR ACEPTAR RECORDSOURCE: Seleccionar Tipo de Comando “2-adcmdTable”, en tabla o nombre de procedimiento almacenado “Elige tu tabla de Access”. Y presiona Aceptar.

description

Pasos para enlazar acces

Transcript of Pasos Para Enlazar Access Con Visual Basic 6

Page 1: Pasos Para Enlazar Access Con Visual Basic 6

PASOS PARA ENLAZAR ACCESS CON VISUAL BASIC 6.01.- Botón secundario sobre el cuadro de herramientas elegir componentes.

2.- En la ventana que aparece seleccionar “Microsoft ADO Data control 6.0 (OLEDB). Presionar Aceptar.

3.- En el cuadro de herramientas aparecera el icono siguiente colocarlo en el formulario.

4.- seleccionar el ADODC1 y modificar las siguientes propiedades:

CONECCIONSTRING:

PRESIONAR ACEPTAR

RECORDSOURCE: Seleccionar Tipo de Comando “2-adcmdTable”, en tabla o nombre de procedimiento almacenado “Elige tu tabla de Access”. Y presiona Aceptar.

5.- En cada caja de texto modifica las propiedades de DATASOURCE elige “Adodc1”, y en DATAFIELD elige el campo a mostrar.

6.- Ejecuta el formulario y listo.

Page 2: Pasos Para Enlazar Access Con Visual Basic 6

CONFIGURAR BOTONES DE SIGUIENTE, ANTERIOR, PRIMERO Y ULTIMO. FORMULARIO DE MOSTRAR.

SIGUIENTE:

Private Sub CmdSiguiente_Click() Adodc1.Recordset.MoveNext If Adodc1.Recordset.EOF Then Adodc1.Recordset.MovePrevious End IfEnd Sub

ANTERIOR:

Private Sub CmdAnterior_Click() Adodc1.Recordset.MovePrevious If Adodc1.Recordset.BOF Then Adodc1.Recordset.MoveNext End IfEnd Sub

PRIMERO:

Private Sub CmdPrimero_Click() Adodc1.Recordset.MoveFirstEnd Sub

ULTIMO:

Private Sub CmdUltimo_Click() Adodc1.Recordset.MoveLastEnd Sub

SALIR:

Private Sub CmdSalir_Click() Unload Me FrmMenu.ShowEnd Sub

Page 3: Pasos Para Enlazar Access Con Visual Basic 6

FORMULARIO DE ALTASBOTON DE AGREGAR

Consideramos que las cajas de texto están desactivadas, al dar clic las activamos para que podamos escribir en ellas.

Private Sub CmdAgregar_Click() Adodc1.Recordset.AddNew Text1.Visible = True Text2.Visible = True Text3.Visible = True Text4.Visible = TrueEnd Sub

BOTON DE GUARDAR

Private Sub CmdGuardar_Click() Adodc1.Recordset.MoveNext Adodc1.Recordset.MovePrevious c = MsgBox("Guardado")End Sub

SALIR:

Private Sub CmdSalir_Click() Unload Me FrmMenu.ShowEnd Sub

Page 4: Pasos Para Enlazar Access Con Visual Basic 6

FORMULARIO DE BAJASBOTON DE MOSTRAR:

Private Sub CmdMostrar_Click() Dim aux As String Adodc1.Refresh aux = UCase(Text5.Text) Adodc1.Recordset.MoveNext If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.Find "NOMBRE = '" & UCase(aux) & "'" End If If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveFirst Adodc1.Recordset.Find "NOMBRE = '" & UCase(aux) & "'" If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast m = MsgBox("NO SE ENCONTRO", vbCritical) Text5.Text = "" Label1.Visible = False Label2.Visible = False Label3.Visible = False Label4.Visible = False Text1.Visible = False Text2.Visible = False Text3.Visible = False Text4.Visible = False Text5.SetFocus End If End If Label1.Visible = True Label2.Visible = True Label3.Visible = True Label4.Visible = True Text1.Visible = True Text2.Visible = True Text3.Visible = True Text4.Visible = True End Sub

BOTON DE ELIMINAR:

Private Sub Command2_Click() With Adodc1.Recordset .Delete .MoveNext If .EOF Then .MoveLast End WithEnd Sub

Page 5: Pasos Para Enlazar Access Con Visual Basic 6

FORMULARIO DE CONSULTASBOTON DE CONSULTAR:

Private Sub CmdConsultar_Click() Dim aux As String Adodc1.Refresh aux = UCase(Text5.Text) Adodc1.Recordset.MoveNext If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.Find "NOMBRE = '" & UCase(aux) & "'" End If If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveFirst Adodc1.Recordset.Find "NOMBRE = '" & UCase(aux) & "'" If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast m = MsgBox("NO SE ENCONTRO", vbCritical) Text5.Text = "" Label1.Visible = False Label2.Visible = False Label3.Visible = False Label4.Visible = False Text1.Visible = False Text2.Visible = False Text3.Visible = False Text4.Visible = False Text5.SetFocus End If End If Label1.Visible = True Label2.Visible = True Label3.Visible = True Label4.Visible = True Text1.Visible = True Text2.Visible = True Text3.Visible = True Text4.Visible = True End Sub

BOTON DE CONSULTAR OTRO:

Private Sub CmdConsulOtro_Click() Text5.Text = "" Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" Text5.SetFocusEnd Sub

Page 6: Pasos Para Enlazar Access Con Visual Basic 6

FORMULARIO DE MODIFICARBOTON DE MOSTRAR:

Private Sub CmdMostrar_Click() Dim aux As String Adodc1.Refresh aux = UCase(Text5.Text) Adodc1.Recordset.MoveNext If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.Find "NOMBRE = '" & UCase(aux) & "'" End If If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveFirst Adodc1.Recordset.Find "NOMBRE = '" & UCase(aux) & "'" If Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast m = MsgBox("NO SE ENCONTRO", vbCritical) Text5.Text = "" Label1.Visible = False Label2.Visible = False Label3.Visible = False Label4.Visible = False Text1.Visible = False Text2.Visible = False Text3.Visible = False Text4.Visible = False Text5.SetFocus End If End If Label1.Visible = True Label2.Visible = True Label3.Visible = True Label4.Visible = True Text1.Visible = True Text2.Visible = True Text3.Visible = True Text4.Visible = TrueEnd Sub

BOTON DE MODIFICAR: Se utiliza un combo para elegir el campo a modificar el cual debe ser cargado desde el formulario.

Private Sub CmdModificar_Click() If Combo1.Text = "NOMBRE" Then Text1.Text = "" Text1.SetFocus End If If Combo1.Text = "DIRECCION" Then Text2.Text = "" Text2.SetFocus End If If Combo1.Text = "TELEFONO" Then

Page 7: Pasos Para Enlazar Access Con Visual Basic 6

Text3.Text = "" Text3.SetFocus End If If Combo1.Text = "EMAIL" Then Text4.Text = "" Text4.SetFocus End If End Sub

BOTON DE GUARDAR:

Private Sub CmdGuardar_Click() Adodc1.Recordset.UpdateBatch adAffectAllEnd Sub

FORMULARIO DE CONTRASEÑAENTRAR AL SIGUIENTE FORMULARIO CON ENTER EN LA CAJA DE TEXTO.

Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = vbKeyReturn Then On Error Resume Next KeyAscii = 0 If UCase(Text1.Text) = "ARTEMIO" And UCase(Text2.Text) = "CHRISTO" Then FrmMenu.Show Unload Me Else c = MsgBox("NOMBRE DE USUARIO Y CONTRASEÑA INCORRECTOS", vbCritical) Text1.Text = "" Text2.Text = "" Text1.SetFocus End If End IfEnd sub

ENTRAR AL SIGUIENTE FORMULARIO CON EL BOTON DE ACEPTARPrivate Sub CmdAceptar_Click() Text1.Text = UCase(Text1.Text) Text2.Text = UCase(Text2.Text) If Text1.Text = "ARTEMIO" And Text2.Text = "CHRISTO" Then FrmMenu.Show Unload Me Else c = MsgBox("NOMBRE DE USUARIO Y CONTRASEÑA INCORRECTOS", vbCritical) Text1.Text = "" Text2.Text = "" Text1.SetFocus End IfEnd Sub

Page 8: Pasos Para Enlazar Access Con Visual Basic 6

CARGAR IMAGEN EN FORMULARIO Y BOTON DE GUARDAR EN ACCESS.

IMAGE: Modificar las siguientes propiedades:

STRETCH colocarla en TRUE: Ajusta la imagen al tamaño especificado.

Colocar una etiqueta para mostrar la imagen y obtener la ruta de la imagen.

Private Sub Label5_Change()

Image1.Picture = LoadPicture(Label5.Caption)

End Sub

En esta etiqueta modifica los campos siguientes:

DATASOURCE coloca Adodc1 y en DATAFIELD el campo Foto de Access, VISIBLE en False

BUSCAR UNA IMAGEN UTILIZANDO EL EXPLORADOR DE WINDOWS.

1.- Botón secundario sobre el cuadro de herramientas y elige componentes.

2.- De la ventana que aparece marca “MICROSOFT COMMON DIALOG CONTROL 6.0” y presiona Aceptar.

3.- Del cuadro de herramientas elige el icono llamado “COMMANDIALOG”, en la propiedad nombre modifícala por “DIALOG1”.

BOTON DE BUSCAR UNA IMAGEN

Private Sub CmdBuscar_Click() Dialog1.ShowOpen Image1.Picture = LoadPicture(Dialog1.FileName) Label5.Caption = Dialog1.FileNameEnd Sub

Page 9: Pasos Para Enlazar Access Con Visual Basic 6

MOSTRAR DATOS DE ACCESS EN UN DATAGRID

Colocar el Adodc1 y conectarlo.

1.- Botón secundario sobre el cuadro de herramientas y elige componentes.

2.- De la ventana que aparece marca “MICROSOFT DATAGRID CONTROL 6.0(OLEDB)” y presiona Aceptar.

3.- Del cuadro de herramientas elige el icono llamado “DATAGRID”, en la propiedad DataSource elige “ADODC1”.

CARGAR EN UN COMBO LOS CAMPOS DE ACCESSSe realiza desde el formulario al arranque. Private Sub Form_Load() For x = 1 To Adodc1.Recordset.Fields.Count - 1 Combo1.AddItem Adodc1.Recordset.Fields.Item(x).Name Next x End Sub

Page 10: Pasos Para Enlazar Access Con Visual Basic 6

FILTRAR REGISTROS CON AUTORELLENO POR EL CAMPO NOMBRE

BOTON FILTRARPrivate Sub CmdFiltrar_Click() Dim aux As String Adodc1.Refresh If Combo1.Text = "NOMBRE" Then aux = Text1.Text Adodc1.Recordset.MoveNext If Not Adodc1.Recordset.EOF Then temp = "NOMBRE LIKE '*" & UCase(aux) & "*'" Adodc1.Recordset.Filter = temp End If End IfEnd Sub

BOTON MOSTRAR TODOPrivate Sub CmdMostrarTod_Click() Adodc1.Refresh Text1.Text = "" Text1.SetFocus Combo1.Text = ""End Sub

MOSTRAR CALENDARIO DE FECHA MEDIANTE UN DTPICKER

1.- Botón secundario sobre el cuadro de herramientas y elige componentes.

2.- De la ventana que aparece marca “MICROSOFT WINDOWS COMMAN CONTROL 2 6.0” y presiona Aceptar.

3.- Del cuadro de herramientas elige el icono llamado “DTPICKER”, en la propiedad DataSource elige “ADODC1” y en DataField elige el campo Fecha.