Microsoft KB Archive/103808: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
Line 44: Line 44:
== SUMMARY ==
== SUMMARY ==


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.
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.


</div>
</div>
Line 61: Line 61:


<ul>
<ul>
<li><p>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 &quot;Index Property (Data Access),&quot; 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:</p>
<li><p>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:</p>
<pre class="codesample">        Data1.RecordSource = &quot;Select * From Publishers Order By PubID&quot;
<pre class="codesample">        Data1.RecordSource = "Select * From Publishers Order By PubID"
                                 </pre>
                                 </pre>
<p>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.</p></li>
<p>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.</p></li>
Line 68: Line 68:
</li>
</li>
<li><p>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:</p>
<li><p>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:</p>
<pre class="codesample">      Data1.Recordset.Sort = &quot;City DESC&quot;   '** No error occurs
<pre class="codesample">      Data1.Recordset.Sort = "City DESC"   '** No error occurs
       Data1.Refresh                        '** No change in order occurs
       Data1.Refresh                        '** No change in order occurs
                         </pre>
                         </pre>
<p>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:</p>
<p>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:</p>
<pre class="codesample">      Data1.RecordSource = &quot;Select * From Publishers Order By City DESC&quot;
<pre class="codesample">      Data1.RecordSource = "Select * From Publishers Order By City DESC"
       Data1.Refresh
       Data1.Refresh
                         </pre></li>
                         </pre></li>
<li>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.</li>
<li>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.</li>
<li>You cannot perform a FileCopy statement on a database while a form that contains a data control is loaded. A &quot;Permission Denied&quot; 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.</li>
<li>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.</li>
<li><p>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:</p>
<li><p>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:</p>
<pre class="codesample">  Sub Command1_Click ()
<pre class="codesample">  Sub Command1_Click ()
Line 83: Line 83:
       Dim Sn As Snapshot
       Dim Sn As Snapshot


       Data1.DatabaseName = &quot;c:\vb\biblio.mdb&quot;
       Data1.DatabaseName = "c:\vb\biblio.mdb"
       Data1.RecordSource = &quot;Authors&quot;
       Data1.RecordSource = "Authors"
       Data1.Refresh
       Data1.Refresh


       ' Open the &quot;By date&quot; query
       ' Open the "By date" query
       Set Qd = Data1.Database.OpenQueryDef(&quot;By date&quot;)
       Set Qd = Data1.Database.OpenQueryDef("By date")
       ' Set the value of the dp parameter
       ' Set the value of the dp parameter
       Qd!dp = 1991
       Qd!dp = 1991
Line 96: Line 96:
       Do Until Sn.EOF
       Do Until Sn.EOF
         For i = 1 To Sn.Fields.Count - 1
         For i = 1 To Sn.Fields.Count - 1
             Print Sn(i) &amp; &quot; &quot;;  'Display results of query
             Print Sn(i) &amp; " ";  'Display results of query
         Next
         Next
         Print
         Print

Revision as of 09:46, 20 July 2020

Knowledge Base


Limitations of the Data Control in Visual Basic Version 3.0

Article ID: 103808

Article Last Modified on 1/8/2003



APPLIES TO

  • Microsoft Visual Basic 3.0 Professional Edition



This article was previously published under Q103808

SUMMARY

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.

MORE INFORMATION

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:

  1. You cannot use a QueryDef requiring a Parameter in the RecordSource property of the data control.
  2. 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.
  3. 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.
  4. 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
                            
  5. 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.
  6. 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.
  7. 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

Keywords: KB103808