When you edit a record for a database, you can use the StatusBar control to notify users of the various properties of the database, such as the name of the table being edited, the date it was created, and the date of the last update.
The following code uses the following objects:
Form named "Frmdataviewer"
StatusBar control named "Sbrdata"
The data control named "Datdata"
Add StatusBar to display database properties
Use the Add method to create a collection of Panel objects.
Configure the AutoSize property for each panel object.
Displays the properties of the database with the Text property of the Panel object.
Reset the property with the Selectcase statement in the Panelclick event.
Create a collection of Panel objects with the Add method
To create a collection of Panel objects at run time, you need to use the Add method. First you need to declare a variable of a panel type. When you add each panel object, you can use the variable to include a reference to the newly created object. The following code creates three panel objects in the Load event of a Form object.
Privatesubform_load ()
Dimpnlxaspanel
Dimiasinteger
Fori=1to3 ' first panel already exists.
Setpnlx=sbrdata.panels.add ()
Nexti
Endsub
Note: After you add three Panel objects to the collection, there are actually four panels in the control because a panel has been created by default in the control.
Configure AutoSize properties for each Panel object
One feature of the StatusBar control is that the panel can automatically resize itself based on its contents. The following example loops through all the Panel objects and sets each AutoSize property to Sbrspring (1). This allows each panel to share the total width of the control through "flex".
Privatesubform_load ()
Dimpnlxaspanel
Dimiasinteger
Fori=1to3 ' first panel already exists.
Setpnlx=sbrdata.panels.add ()
Nexti
' Change the autosize of all the panels.
Fori=1to4 ' <--new code
Sbrdata.panels (i). Autosize=sbrspring ' New
Nexti ' New
Endsub
Display the properties of a database with the Text property of the Panel object
To change the information displayed in all panels, simply set the Text property of the Panel object. The following code shows information about the database that was opened by the data Access object.
In the Form object's Load event, you first create two database variables and assign them to open databases (Biblio.mdb) and Recordset (Authors) respectively. The code then assigns the values of the name, DateCreated, LastUpdated, and Lockedit properties to the Text property of each Panel object.
' Declares a database variable.
Dimmydbasdatabase,myrsasrecordset
' Set the database to Biblio.mdb.
Setmydb=dbengine.workspaces (0). _
OpenDatabase ("BIBLIO.") MDB ")
' Set the recordset variable to the authors table.
Setmyrs=_
Mydb.openrecordset ("publishers", dbOpenTable)
' Set the Text property to the Recordset property.
Sbrdata.panels (1). text= "Name:" &myrs.name
Sbrdata.panels (2). text= "Date Created:" &_
myrs.datecreated
Sbrdata.panels (3). Text= "Last Modified Date:" &_
myrs.lastupdated
Sbrdata.panels (4). text= "edit Lock:" &myrs.lockedits
To reset a property with the Selectcase statement in the Panelclick event
The StatusBar control can also be used to reset the properties that are being displayed. In the above application instance, the DataGrid control is bound to the data control. (For more information about how to implement data binding for a control, see "Using ADO Data Controls" in the Programmer's Guide, "using the VisualBasic Standard Control"). Only LockEdits properties can be reset in the properties displayed by the StatusBar. To do this, you can use the Selectcase statement in the Panelclick event to determine which panel object was clicked. The Panelclick event contains a reference to the panel that was clicked. Use this reference to reset the Text property of the Panel object that you clicked.
The following code first creates a variable of the recordset type and sets it to the set of records opened by the data control. The Selectcase statement is used to detect the Index property of a Panel object. If index is 4, the LockEdits property toggles between -1 (True) and 0 (False). Finally, the Text property of the Panel object is updated with the new information.
Privatesubsbrdata_panelclick (Byvalpanelaspanel)
Dimmyrsasrecordset ' declares a recordset variable.
' The name of the data control is ' Datdata '
Setmyrs=datdata.recordset ' Set variable.
Selectcasepanel.index
Case1to3
' Cannot set these panels.
Case4 ' updateablepropertyissettable.
' Toggle the property.
Myrs.lockedits=abs (myrs.lockedits)-1
' Update the Text property of the Panel object.
Sbrdata.panels (4). text= "LockEdits:" _
&myrs.lockedits
Endselect
Endsub