The information in this article applies to:
SUMMARYThis article describes and demonstrates techniques you can use to change (toggle on or off) read-only access of a data control or database at run time. All behavior discussed in this article is by design. MORE INFORMATIONNotes to Remember When Changing Read-Only AccessFor database object variables, you must close all database variables opened for a given database before you can change its read-only access. Use the Close method to close a database object stored in a variable. Use the OpenDatabase function with a parameter to specify the read-only access for the opened database.For a data control, you must use the Refresh method to reset the data control after you change its read-only access by changing the ReadOnly property. Another more complicated way to reset the data control is to unload the form, which closes the data control. Then use Load and Show to reload the display form. You must set the data control's new ReadOnly property value in the Form Load event procedure, or else ReadOnly will use its design-time setting. The read-only parameter of the OpenDatabase function will be ignored at run time when you open a database that is currently bound to a data control. To change the read-only access of a bound database at run time, you must set the ReadOnly property for the data control and use the Refresh method. The ReadOnly property of a data control will retain the value that you set, but the new ReadOnly property won't take effect until you use the Refresh method. For example, if you change the ReadOnly property from True to False and fail to use the Refresh method, the database bound to the data control will remain read-only even though the ReadOnly property does contain the new value of False. You must execute the Refresh method on the data control to tell the bound database that you changed the ReadOnly property. The following examples demonstrate how to change the read-only access of a database at run time. Close Database Before Changing Read-Only AccessThe following two examples demonstrate that you must close a database before changing the read-only access (False = 0, True = -1).Example One -- Using Database Object Variables: Open database A and set the read-only parameter to True. Without closing database A, open database A a second time and set read-only access to False. The second open uses read-only access, ignoring your request for read-only to be False. This behavior is by design. The following code example demonstrates this behavior:
By definition, the Updatable property returns False when the read-only
access is True, and vice versa. In the above example, the Updatable
property of database variable d2 remains False from the first open,
despite your request to turn off read-only access.To reset the read-only access, close the database first. Then change the read-only access. For example:
Database variable d1 is erased by the Close. The Updatable property of the
second database variable (d2) will be False, as desired. Updatable returns
False when the database was opened with read-only access.Example Two -- Using a Text Control Bound to a Data Control: A data control does implicit OpenDatabase and CreateDynaset function calls at load time using design-time properties such as DatabaseName, RecordSource, and ReadOnly. If you change the ReadOnly property of a data control at run time, you must use the Refresh method to reset the database. The following steps show how to do it:
You Can Open Different Databases with Different Read-only AccessEach different database you open can have a different read-only setting. In the following example, d1.Updatable will be True and d2.Updatable will be False, because they refer to different databases:
Additional query words: 3.00 R/W status lock locking how-to
Keywords : |
Last Reviewed: September 16, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |