Microsoft KB Archive/102479: Difference between revisions
(importing KB archive) |
m (Text replacement - """ to """) |
||
Line 65: | Line 65: | ||
Use the domain aggregate functions within an SQL statement, as in the following example. Enter the following as one, single line: | Use the domain aggregate functions within an SQL statement, as in the following example. Enter the following as one, single line: | ||
<pre class="codesample"> Set Dn = Db.CreateDynaset( | <pre class="codesample"> Set Dn = Db.CreateDynaset("Select DAvg(""AU_ID"", ""AUTHORS"") | ||
FROM Authors | FROM Authors")</pre> | ||
</div> | </div> | ||
Line 92: | Line 92: | ||
Dim Dn As Dynaset | Dim Dn As Dynaset | ||
Set Db = OpenDatabase( | Set Db = OpenDatabase("C:\VB\BIBLIO.MDB") | ||
' Note: enter the following Set Dn code as one, single line. | ' Note: enter the following Set Dn code as one, single line. | ||
Set Dn = Db.CreateDynaset( | Set Dn = Db.CreateDynaset("Select DAvg(""AU_ID"", ""AUTHORS"") | ||
FROM Authors | FROM Authors") | ||
Print Dn(0) ' This is the equivelant of | Print Dn(0) ' This is the equivelant of | ||
' Form1.Print Dn.Fields(0).Value | ' Form1.Print Dn.Fields(0).Value |
Latest revision as of 09:21, 20 July 2020
Article ID: 102479
Article Last Modified on 10/28/2003
APPLIES TO
- Microsoft Visual Basic 3.0 Professional Edition
- Microsoft Visual Basic 3.0 Professional Edition
This article was previously published under Q102479
SYMPTOMS
If you try to use the domain aggregate function examples provided in the Microsoft Visual Basic version 3.0 for Windows Help file, you will receive this error message:
CAUSE
The examples for the domain aggregate functions are incorrect. The domain aggregate functions, like the SQL aggregate functions, can be used only within an SQL statement.
WORKAROUND
Use the domain aggregate functions within an SQL statement, as in the following example. Enter the following as one, single line:
Set Dn = Db.CreateDynaset("Select DAvg(""AU_ID"", ""AUTHORS"") FROM Authors")
STATUS
Microsoft has confirmed this to be a bug in the Visual Basic version 3.0 Help file. This problem has been corrected in Visual Basic version 4.0.
MORE INFORMATION
Step-by-Step Example
The following example demonstrates how to print to the form an average of all the AU_ID values in the Authors table from the BIBLIO.MDB database that comes with Microsoft Visual Basic version 3.0 for Windows:
- Start Visual Basic or from the File menu, choose New Project if Visual Basic is already running. Form1 is created by default.
Add the following code to the Click event of Form1:
Sub Form_Click() Dim Db As Database Dim Dn As Dynaset Set Db = OpenDatabase("C:\VB\BIBLIO.MDB") ' Note: enter the following Set Dn code as one, single line. Set Dn = Db.CreateDynaset("Select DAvg(""AU_ID"", ""AUTHORS"") FROM Authors") Print Dn(0) ' This is the equivelant of ' Form1.Print Dn.Fields(0).Value ' It is always a good idea to close the database objects: Dn.Close Db.Close End Sub
- Run the example. Then click the form.
All the other domain aggregate functions work in a similar way. It is only the example that is incorrect in the Visual Basic Help file. The other information explaining how to use the function parameters is correct.
The Following are the Domain Aggregate Functions:
DAvg
DCount
DFirst
DLast
DLookup
DMin
DMax
DStDev
DStDevP
DSum
DVar
DVarP
Additional query words: buglist3.00 3.00 fixlist4.00
Keywords: kbbug kbfix KB102479