Microsoft KB Archive/103808
Article ID: 103808
Article Last Modified on 1/8/2003
- Microsoft Visual Basic 3.0 Professional Edition
This article was previously published under Q103808
Chapter 20 in the "Programmer's Guide" explains how to use a data control in Microsoft Visual Basic version 3.0 for Windows. You may want to use an object variable such as Snapshot instead of using the data control. Chapter 20 does not explain the limitations of using the data control, so this article lists those limitations for you.
Because a data control is a special type of Dynaset, its limitations are similar to those of Dynasets. Here are the limitations of data controls:
- You cannot use a QueryDef requiring a Parameter in the RecordSource property of the data control.
- Using a data control along with other bound controls uses System Resources (memory). When you build larger programs, you may want to look at other programming methods (Database objects don't require controls, therefore you don't use System Resources) to display your database data.
- Not every method and property specific to the Table object can be performed by the data control. Here are two such cases:
You cannot take advantage of the Index property of the Table object to display your database data in a specific indexed order with the data control. This technique, described in the example shown in the Help file topic "Index Property (Data Access)," works only with the Table object, not the data control. As an alternative, you can use an ORDER BY clause in an SQL statement, as in this example:
Data1.RecordSource = "Select * From Publishers Order By PubID"
The ORDER BY clause technique is also more flexible than the Index property technique. Using the ORDER BY clause, you can sort on any field, and no specified index is required.
- You cannot use a Seek method on your database data for a specific record with the data control. The Seek method can only be used by the Table object. You can, however, perform a FindFirst method with the data control.
You cannot use the Sort property on a specific database record with the data control. The Sort property technique is specific to a Dynaset or Snapshot object. The following example proves this limitation:
Data1.Recordset.Sort = "City DESC" '** No error occurs Data1.Refresh '** No change in order occurs
If you try to sort the Publishers table by City, nothing happens. But if you use an ORDER BY clause in an SQL statement, as in the following example, you will see the database data displayed in descending order by the City names:
Data1.RecordSource = "Select * From Publishers Order By City DESC" Data1.Refresh
- A data control is bound to one, single form -- the form on which it resides. Therefore, when the form that contains the data control is not loaded, you cannot refer to the data control from another form.
- You cannot perform a FileCopy statement on a database while a form that contains a data control is loaded. A "Permission Denied" error occurs if you try to use the FileCopy statement to make a backup of your database while a form containing a data control is loaded in memory. To prevent this error, first close or unload the form that contains the data control. Then run the FileCopy statement to make a database backup.
You cannot use a data control to display the results of a parameter query. It is possible to use the Database object of the data control to open and run a querydef which requires parameters. For example:
Sub Command1_Click () Dim db As Database Dim Qd As QueryDef Dim Sn As Snapshot Data1.DatabaseName = "c:\vb\biblio.mdb" Data1.RecordSource = "Authors" Data1.Refresh ' Open the "By date" query Set Qd = Data1.Database.OpenQueryDef("By date") ' Set the value of the dp parameter Qd!dp = 1991 ' create a snapshot off of querydef Set Sn = Qd.CreateSnapshot() Sn.MoveFirst Do Until Sn.EOF For i = 1 To Sn.Fields.Count - 1 Print Sn(i) & " "; 'Display results of query Next Print Sn.MoveNext Loop Sn.Close Qd.Close db.Close End Sub
Additional query words: 3.00 docerr