473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I write an expression for SetTempVar to = the value of a field in an open qry?

In my macro....

First I OpenQuery
Then I GoToRecord (First)
Next, I would like to set the Expression of SetTempVar to equal the value of a field in the first record of the open query... but I am stumped on how to do this.
Dec 29 '10 #1

✓ answered by ADezii

Expand|Select|Wrap|Line Numbers
  1. Dim strQueryName As String
  2. Dim strFieldName As String
  3. Dim rst As DAO.Recordset
  4. Dim varRetVal As Variant
  5.  
  6. '*************** Make your own substitutions here ***************
  7. strQueryName = "qryOrderDetails"
  8. strFieldName = "OrderID"
  9. '****************************************************************
  10.  
  11. Set rst = CurrentDb.OpenRecordset(strQueryName, dbOpenSnapshot)
  12.  
  13. 'Make sure that there is at least 1 Record
  14. If Not rst.BOF And Not rst.EOF Then
  15.   varRetVal = rst(strFieldName)
  16.   Debug.Print "The Value of the [" & strFieldName & "] Field in the 1st Record " & _
  17.             "of the Query " & strQueryName & " is " & varRetVal & "."
  18. End If

3 9081
ADezii
8,834 Expert 8TB
Is your request to set the Value of a Variable to a specific Field in the 1st Record of a Query?
Dec 29 '10 #2
Yes. For example, the field value may be 99991. I want to set the Value of the Variable to 99991.

First I OpenQuery
Then I GoToRecord (First)
Next, I would like to set the Expression of SetTempVar to equal the value of a field in the first record of the open query... but I am stumped on how to do this.
Dec 29 '10 #3
ADezii
8,834 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. Dim strQueryName As String
  2. Dim strFieldName As String
  3. Dim rst As DAO.Recordset
  4. Dim varRetVal As Variant
  5.  
  6. '*************** Make your own substitutions here ***************
  7. strQueryName = "qryOrderDetails"
  8. strFieldName = "OrderID"
  9. '****************************************************************
  10.  
  11. Set rst = CurrentDb.OpenRecordset(strQueryName, dbOpenSnapshot)
  12.  
  13. 'Make sure that there is at least 1 Record
  14. If Not rst.BOF And Not rst.EOF Then
  15.   varRetVal = rst(strFieldName)
  16.   Debug.Print "The Value of the [" & strFieldName & "] Field in the 1st Record " & _
  17.             "of the Query " & strQueryName & " is " & varRetVal & "."
  18. End If
Dec 29 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tommy | last post by:
I am a complete beginner in regular expressions and would need some help from the group regarding checking a form field. I have a field on the form where users enters a text string. The user...
5
by: MLH | last post by:
I have this expression in a query ... Trim$(Left$(,-1)) It evaluates to "1/16" How can I convert that to the numeric value 0.0625?
1
by: Sam | last post by:
Hi, I don't know how to specify the display and value field for a combobox when using AddRange to fill the combo. Here is what I have so far: -A function to build an array of object : Dim...
1
by: arulbenito | last post by:
i need to write a xml data inside the value field in web.config file. it looks likes this <configuration> <appSettings> <add key="MyXmlData" value="<data><type></type>........." />...
1
by: somanyusernamesaretakenal | last post by:
Hi everyone, I am working with Access 2003. I know a crosstab query only allows 1 value field, but how to do you around this restriction? I have a table with let’s say customers, products,...
10
by: Hugh Middity2 | last post by:
Hello, is there a parameter value field in access that can be passed between queries, forms and reports? For example, we have two companies both selling the same products. To extract data we have to...
1
by: Proaccesspro | last post by:
How can I store the value of an expression I am calculating on a form to a field in a database?
4
by: AR123 | last post by:
In the field for employee contribution I want to have GBP and make sure that this prints out in the results email. How can I set it up so that the GBP display next to the value in the results email?...
15
by: amy1 | last post by:
Hello everyone, I'm new here and new to Access2007 as well! I have a multi-value field in a form, and would like to calculate the total of the selected values in this field and place the...
1
by: Leah Beard | last post by:
I have a table with a stored hyperlink field and in the report from the table i want view the hyperlink, so i need to write a event procedure to open the hyperlink when a text box is clicked in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.