Assigning the results of a query to a variable 
Author Message
 Assigning the results of a query to a variable

In an old message, someone says that this (assigning the results of a
query to a variable) has been done in DAO?  Does he mean there is
another way, using DAO, to do this or that the solution he proposes is
how to do this using DAO?

If there is another way, using DAO, could someone point me to that
command?

Thanks,
Nolan Madson

Ian

'add this to the start of your code
dim rs as recordset
dim newvariable as integer ' assuming this is appropriate
set rs = db.openrecordset(qdf,dbopensnapshot) ' if snapshot is
required 'and this at the end
newvariable = rs!MaxOfJB_CONTRACT_NO

the newvariable variable now contains your value

This has been done in DAO!
Happy programming!
David


Quote:
> Hi

> I want to run a query from a module, and then assign the results to a
> varible. The following run the query but how do i get to the value it
> return.

> Dim dbs As Database, qdf As QueryDef
>    Dim strSQL As String

>    ' Return reference to current database.
>    Set dbs = CurrentDb
>    ' Refresh QueryDefs collection.
>    dbs.QueryDefs.Refresh
>    ' If RecentHires query exists, delete it.
>    For Each qdf In dbs.QueryDefs
>        If qdf.Name = "MaxContract" Then
>            dbs.QueryDefs.Delete qdf.Name
>        End If
>    Next qdf

> strSQL = "SELECT Max(Jobs.JB_CONTRACT_NO) AS MaxOfJB_CONTRACT_NO FROM
Jobs;"

> ' Create new QueryDef object.
>    Set qdf = dbs.CreateQueryDef("MaxContract", strSQL)
>      Set dbs = Nothing

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


Sat, 04 May 2002 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Assigning the results of a query to a variable (cont)

2. Assign result of qry to variable

3. SQL result assigned to variable - HOW?

4. Assign result of qry to variable

5. assigning query return to a variable

6. assign NULL values from query to variables

7. assign NULL values from query to variables

8. Modules: setting a variable in memory to the results of a query (EXCEL AUTOMATION)

9. Placing Result of Query into Variable

10. Using a query result as a variable in code

11. how do I get an sql query to return result to a variable

12. Saving results of query into variables with multiple types

 

 
Powered by phpBB® Forum Software