Nota acerca de su sistema operativoEste artículo se aplica a un sistema operativo distinto al que usa. El contenido del artículo que puede que no sea importante para usted, se deshabilitará
En este artículo se muestra cómo simular una barra de progreso en un formulario mediante los controles de rectángulo en el cuadro de herramientas Microsoft Access. En este ejemplo, crear un formulario que utiliza objetos de acceso a datos (DAO) o ActiveX Data Objects (ADO) para leer datos de la tabla Customers. Como Access lee cada registro, el código de formulario rellena otra pieza de la barra de progreso. Nota : Si decide utilizar ADO para leer los registros, debe tener el Data Engine (MSDE) o Microsoft SQL Server instalado. Además, debe tener Neptuno o NeptunoCS instalados en el MSDE o SQL Server.
Crear una nueva base de datos Access e importar la tabla Customers
Inicie Microsoft Access.
Crear una nueva base de datos y asígnele el nombre ProgressBar .
En el menú archivo , elija Obtener datos externos y, a continuación, haga clic en Importar .
En el cuadro de diálogo Importar , busque Neptuno.mdb y, a continuación, haga clic en Importar .
En el cuadro de diálogo Importar objetos , haga clic en la tabla Customers y, a continuación, haga clic en Aceptar .
Crear el formulario
Abra la base de datos ProgressBar que creó anteriormente.
En el menú Ver , seleccione Objetos de base de datos y, a continuación, haga clic en formularios .
Haga clic en nuevo . En el cuadro de diálogo Nuevo formulario , asegúrese de que está activada la Vista Diseño y, a continuación, haga clic en Aceptar .
Agregar los objetos siguientes al formulario y establezca las siguientes propiedades:
Form: frmProgressBar
-------------------------
Caption: Progress Bar Form
Width: 6.333"
General Declarations:
Dim lCounter As Long
OnOpen:
' Make sure, when the form is initially opened, that the status caption reads READY.
Me.Status.Caption = "Ready"
En este ejemplo de código se utiliza ADO. Escriba o pegue el siguiente procedimiento:
' As soon as you click the command button, start reading records.
' Because you've started reading records, update the status caption to
' READING.
Me.Status.Caption = "Reading"
' For the currently open form, display a busy/hourglass mouse icon.
Screen.MousePointer = 11
' Dimension the connection and recordset objects for using ADO.
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
' Set the connection properties.
' ==================================================================
' BEGIN - Using ADO connection to local table.
' ==================================================================
' Use Set cn = CurrentProject.Connection to connect to a local table
' using ADO.
Set cn = CurrentProject.Connection
' ==================================================================
' END - Using ADO connection to local table.
' ==================================================================
' ==================================================================
' BEGIN - Using new ADO connection to SQL Server.
' ==================================================================
' If you want to connect to a SQL Server using ADO, then uncomment these
' lines of code and comment out the "Using ADO connection to local
' table" code above.
' With cn
' .Provider = "SQLOLEDB"
' Change the Data Source name to your SQL Server.
' The current connection string specifies integrated
' security. You may have to change this.
'.ConnectionString = "Data Source=TestSQL; Integrated Security=SSPI;Initial Catalog=Northwind"
' Open the connection.
'.Open
'End With
' ==================================================================
' END - Using new ADO connection to SQL Server.
' ==================================================================
' Set the recordset object to the Customers table.
Set rs = New ADODB.Recordset
With rs
Set .ActiveConnection = cn
.CursorLocation = adUseClient
.Source = "Customers"
.Open
' While there are still records to be read, display the current customer
' ID number and fill the progress bar to the current record's location,
' based on the total number of records in the Customers recordset.
While Not .EOF
' Set the form's record ID number text box equal to the current record
' being read.
CurrentRecordID = .Fields("CustomerID")
' Set the width of the visible (or top) progress bar rectangle.
ProgressBarB.Width = (ProgressBarA.Width / .RecordCount) * .AbsolutePosition
' Repaint the current form.
Me.Repaint
' Move to the next record.
.MoveNext
For lCounter = 1 To 750000: Next
Wend
End With
' If you're at the end of the Customers recordset, then fill the
' progress bar completely and repaint the form.
If rs.EOF Then
ProgressBarB.Width = rs.RecordCount
Me.Repaint
' Clear any customer ID information from the form because you're finished.
' Set the caption for the Status label to DONE.
CurrentRecordID = ""
Me.Status.Caption = "Done"
' Set the progress bar's width to zero. Repaint the form.
ProgressBarB.Width = 0
Me.Repaint
End If
' Close the recordset.
rs.Close
' Close the connection.
cn.Close
' Clear the recordset and database objects.
Set rs = Nothing
Set cn = Nothing
' Set the form's mouse pointer back to the default mouse pointer.
Screen.MousePointer = 0
Método DAO
En este ejemplo de código se utiliza DAO. Para que este código funcione correctamente, debe hacer referencia a la biblioteca de objetos Microsoft DAO 3.6. Para ello, siga estos pasos:
En el menú Ver , seleccione Objetos de base de datos y, a continuación, haga clic en módulos . Haga clic en nuevo .
En el menú Herramientas , haga clic en referencias . Busque la biblioteca de objetos Microsoft DAO. Active la casilla de verificación Biblioteca de objetos Microsoft DAO 3.6 y, a continuación, haga clic en Aceptar .
Cierre el módulo nuevo sin guardarlo.
Escriba o pegue el siguiente procedimiento:
' As soon as you click the command button, start reading records. Because
' you've started reading records, update the status caption to READING.
Me.Status.Caption = "Reading"
' For the currently open form, display a busy/hourglass mouse icon.
Screen.MousePointer = 11
' Dimension the database and recordset objects for using DAO.
Dim db As DAO.Database
Dim rs As DAO.Recordset
' Set the database object to the currently opened database.
' Set the recordset object to the Customers table.
Set db = CurrentDb
Set rs = db.OpenRecordset("Customers", dbOpenSnapshot)
' Go to the first record in the Customers recordset/table.
rs.MoveFirst
' While there are still records to be read, display the current customer
' ID number and fill the progress bar to the current record's location,
' based on the total number of records in the Customers recordset/table.
While Not rs.EOF
' Set the form's record ID number text box equal to the current record
' being read.
CurrentRecordID = rs!CustomerID
' Set the width of the visible (or top) progress bar rectangle.
ProgressBarB.Width = (ProgressBarA.Width / rs.RecordCount) * rs.AbsolutePosition
' Repaint the current form.
Me.Repaint
' Go to the next record in the Customers recordset/form.
rs.MoveNext
For lCounter = 1 To 750000: Next
Wend
' If you're at the end of the Customers recordset/form, then fill the
' progress bar completely and repaint the form.
If rs.EOF Then
ProgressBarB.Width = rs.RecordCount
Me.Repaint
' Clear any customer ID information from the form because you're finished.
CurrentRecordID = ""
' Set the caption for the Status label to DONE.
Me.Status.Caption = "Done"
' Set the progress bar's width to zero. Repaint the form.
ProgressBarB.Width = 0
Me.Repaint
End If
' Close the recordset.
rs.Close
' Clear the recordset and database objects.
Set rs = Nothing
Set db = Nothing
' Set the form's mouse pointer back to the default mouse pointer.
Screen.MousePointer = 0
Quitar la etiqueta para el cuadro de texto CurrentRecordID.
Asegúrese de que ProgressBarA aparece directamente sobre ProgressBarB en el formulario. Para asegurarse de que esto sucede, haga clic en ProgressBarA y, a continuación, haga clic en Enviar al fondo en el menú formato . A continuación, haga clic en ProgressBarB y haga clic en Traer al frente en el menú formato .
Compile el código y, a continuación, guarde el formulario.
Abra el formulario en la vista formulario. Observe que aparece "Listo" en la etiqueta de estado.
Haga clic en el botón de lectura y observe que la etiqueta de estado cambia a "Lecturas". Cuando se hayan procesado todos los registros, la barra de progreso está completamente llena de izquierda a derecha y "Listo" aparece en la etiqueta de estado.
IMPORTANTE: Este artículo ha sido traducido por un software de traducción automática de Microsoft (http://support.microsoft.com/gp/mtdetails) en lugar de un traductor humano. Microsoft le ofrece artículos traducidos por un traductor humano y artículos traducidos automáticamente para que tenga acceso en su propio idioma a todos los artículos de nuestra base de conocimientos (Knowledge Base). Sin embargo, los artículos traducidos automáticamente pueden contener errores en el vocabulario, la sintaxis o la gramática, como los que un extranjero podría cometer al hablar el idioma. Microsoft no se hace responsable de cualquier imprecisión, error o daño ocasionado por una mala traducción del contenido o como consecuencia de su utilización por nuestros clientes. Microsoft suele actualizar el software de traducción frecuentemente.
Haga clic aquí para ver el artículo original (en inglés): 304581
(http://support.microsoft.com/kb/304581/en-us/
)
¿Cuánto esfuerzo ha dedicado personalmente para usar este artículo?
Muy poco
Poco
Moderado
Mucho
Muchísimo
Díganos las razones y qué podemos hacer para mejorar esta información
¡Muchas gracias! Sus comentarios nos ayudarán a mejorar los contenidos de soporte. Para más opciones de asistencia, visite la página de Ayuda y soporte técnico.