Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi,I would like to run a particular query and obtain the value returned by the query and assign to a variable. For eg.When the user clicks on a particular field in the form my procedure using the DoCmd.OpenQuery "QueryName" runs the query. This query will return only 1 record everytime. I want to assign the value returned to a variable in VB. Can anyone let me know how this can be done?Many thanks!!!
AjarnMark
SQL Slashing Gunting Master
3246 Posts
Posted - 2004-04-01 : 17:53:56
I don't know if this can be done by using DoCmd.OpenQuery, but if you're willing to write the VB module code you can use a Recordset object to retrieve the record and then extract the value with the Recordset's Fields.Item(index number or field name). And you can point to the current database for the connection information using CurrentProject.Connection--------------------------------------------------------------Find more words of wisdom at [url]http://weblogs.sqlteam.com/markc[/url]
jsmith8858
Dr. Cross Join
7423 Posts
Posted - 2004-04-01 : 18:11:31
Look up the DLOOKUP(), DMAX(), DMIN() and DSUM() functions in Access help. Very handy.Pass in the column you wish to return, the table/query to get it from, and a WHERE clause.e.g.,
dim a as currencya = Dlookup("Total","Order","OrderID=123")
or
a = DSum("Total","Orders","OrderDate between #1/1/2003# and #12/31/2003#")
you get the idea .....- Jeff
vgunas1
Starting Member
18 Posts
Posted - 2004-04-02 : 12:46:15
Hi,Thanks a lot!! I used the DLookup function and it worked. Am grateful for the help.Thanks again.