StatusBar displays database attributes

Source: Internet
Author: User
Tags mdb database

When editing a database record, you can use the StatusBar control to notify users of various attributes of the database, such as the name of the table being edited, its creation date, and the last update date.

The following code uses the following objects:

Form named "frmDataviewer"

StatusBar control named "sbrData"

Data Control named "datData"

Add StatusBar to display database Properties

Use the Add method to create a set of Panel objects.

Configure the AutoSize attribute for each Panel object.

Use the Text attribute of the Panel object to display the database attributes.

In the PanelClick event, use the SelectCase statement to reset the attributes.

Use the Add method to create a set of Panel objects

To create a set of Panel objects at run time, use the Add method. First, you must declare a Panel variable. When adding a Panel object, you can use this variable to include references to the newly created object. The following code creates three Panel objects in the Load event of the Form object.

PrivateSubForm_Load ()

DimpnlXAsPanel

DimiAsInteger

Fori = 1to3' the first panel already exists.

SetpnlX = sbrData. Panels. Add ()

Nexti

EndSub

Note: After three Panel objects are added to the set, the control actually has four panels because a Panel is created in the control.

Configure the AutoSize attribute for each Panel object

One feature of the StatusBar control is that the Panel can automatically change the size according to its own content. In the following example, all Panel objects are cyclically traversed and each AutoSize attribute is set to sbrSpring (1 ). In this way, each panel shares the total width of the control through "Scaling.

PrivateSubForm_Load ()

DimpnlXAsPanel

DimiAsInteger

Fori = 1to3' the first panel already exists.

SetpnlX = sbrData. Panels. Add ()

Nexti

'Change the AutoSize of all panels.

Fori = 1to4' <-- New Code

SbrData. Panels (I). AutoSize = sbrspring' new

Nexti' new

EndSub

Display the database attributes with the Text attribute of the Panel object

To change the information displayed on all panels, you only need to set the Text attribute of the Panel object. The following code displays information about the database opened by the Data Access Object.

In the Load event of the Form object, create two database variables and assign values to the opened database (Biblio. mdb) and record set (Authors) respectively ). The Code then assigns the value of the Name, DateCreated, LastUpdated, and LockEdit attributes to the Text attribute of each Panel object.

'Declare database variables.

DimmyDBAsDatabase, myRsAsRecordset

'Set the Database to the BIBLIO. MDB Database.

SetmyDB = DBEngine. Workspaces (0 )._

OpenDatabase ("BIBLIO. MDB ")

'Set the record set variable to the Authors table.

SetmyRs = _

MyDB. OpenRecordset ("Publishers", dbOpenTable)

'Set the Text property to the record set property.

SbrData. Panels (1). Text = "Name:" & myRs. Name

SbrData. Panels (2). Text = "created on :"&_

MyRs. DateCreated

SbrData. Panels (3). Text = "Last modified Date :"&_

MyRs. LastUpdated

SbrData. Panels (4). Text = "Edit lock:" & myRs. LockEdits

Reset attributes in the PanelClick event using the SelectCase statement

The StatusBar control can also be used to reset the properties that are being displayed. In the preceding application instance, The DataGrid Control is bound to the Data Control. (For details about how to bind controls to data, see "use ADO Data Controls" in "Use Visual Basic standard controls" in the programmer's Guide "). Only the LockEdits attribute can be reset in the attributes displayed in the StatusBar. To do this, you can use the SelectCase statement in the PanelClick event to determine which Panel object to click. The PanelClick event contains references to the clicked Panel. You can use this reference to reset the Text attribute of the clicked Panel object.

The following code first creates a Recordset variable and sets it to the record set opened by the Data Control. The SelectCase statement is used to check the Index attribute of the Panel object. If the Index is 4, The LockEdits attribute is switched between-1 (True) and 0 (False. Finally, use the new information to update the Text attribute of the Panel object.

PrivateSubsbrData_PanelClick (ByValPanelAsPanel)

DimmyRsAsRecordset 'declares the Recordset variable.

'Data Control name: "datData"

SetmyRs = datData. Recordset 'sets the variable.

SelectCasePanel. Index

Case1to3

'You cannot set these panels.

Case4 'updateablepropertyissettable.

'Switch this attribute.

MyRs. LockEdits = Abs (myRs. LockEdits)-1

'Update the Text attribute of the Panel object.

SbrData. Panels (4). Text = "LockEdits :"_

& MyRs. LockEdits

EndSelect

EndSub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.