' Make sure, when the form is initially opened, that the status caption reads READY.
Me.Status.Caption = "Ready"
' 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
' 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