Domain Aggregate function to return Collection/array 
Author Message
 Domain Aggregate function to return Collection/array

   I decided to re-write several subs that each use recordsets to
iterate a table and process a single value (field).  Since I couldn't
find a domain aggregate function to do the iteration , I wrote my own:

--- cut here ---

'Domain Aggregate function to return the specified record(s) as a
Public Function DQuery(strField As String, _
 strTable As String, strWhere As String) _
 As Collection

   On Error GoTo Badness

   'Create a temporary querydef using supplied params.
   Dim qdef As DAO.QueryDef
   Set qdef = Application.CurrentDb.CreateQueryDef("", _
"Select [" & strField & "] From " & _
 strTable & " Where " & strWhere & ";")

   'Run the query and get the results in a Snapshot
   Dim rsetResults As DAO.Recordset
   Set rsetResults = qdef.OpenRecordset(dbOpenSnapshot)

   'Where the results go
   Dim clnResults As New Collection

   'Check for empty recordset
   If (rsetResults.RecordCount > 0) Then

      'Iterate the results and add items to the results collection
      While Not rsetResults.EOF
         clnResults.Add (rsetResults.Fields(0))

   End If

   rsetResults.Close: Set rsetResults = Nothing
   qdef.Close: Set qdef = Nothing

   Set DQuery = clnResults
   Exit Function

   MsgBox Err.Description, vbCritical, "Error " & Err.Number & " in
   Set DQuery = Nothing

End Function
--- cut here ---

Sent via http://www.*-*-*.com/
Before you buy.

Sat, 25 Jan 2003 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Domain Aggregate Function problem

2. DAO didn't recognize Domain Aggregate functions

3. Missing Domain Aggregate functions in VB5

4. Help using Domain Aggregate Functions in VB5/6

5. Domain Aggregate Functions

6. Jet Domain Aggregate Functions & Visual Basic

7. Domain Aggregate Functions

8. Array in array returned by function

9. new type of aggregate function (product function)

10. Yet Another Domain Aggregate Problem

11. Domain Aggregate Problem

12. domain pruefen domain provider es domain registrieren domain angebot no domain


Powered by phpBB® Forum Software